package com.dhcc.DRGsHosp.web.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openkoala.koala.commons.InvokeResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dhcc.DRGsHosp.facade.DrgsIndexCalFacade;
import com.dhcc.DRGsHosp.facade.WordDRGsReportFacade;
import com.dhcc.DRGsHosp.facade.dto.ParamMap;
import com.dhcc.DRGsHosp.infra.util.Arith;
import com.dhcc.DRGsHosp.pdfRender.utils.GetAbnormity;
import com.dhcc.DRGsHosp.pdfRender.utils.ResourceLoader;

import freemarker.template.Configuration;
import freemarker.template.Template;
/**
 * 
  * @Description:简版新版分析报告导出
  * @Author:ShaoZhiYuan
  * @Date:2017年2月14日 下午5:23:52 
  * @version :2.3.2
  * @copyright:DHC 2015-2016
 */
@Controller("drgsHospWebController43")
@RequestMapping("/WordDRGsReport")
public class WordDRGsReportController {
	@Inject
	private WordDRGsReportFacade wordDRGsReportFacade;
	@Inject
	private DrgsIndexCalFacade drgsIndexCalFacade;

	Map<String,Object> finalmap= new HashMap<String,Object>();
	Map<String,Object> paramMap= new HashMap<String,Object>();
	String errMsg="";
	
	/**
	 * @methodname :getBenchmarkYear
	 * @Description :获取标杆年份
	 * @author:LiuHongjun
	 * @return InvokeResult
	 * @date :2016年12月30日
	 */
	@ResponseBody
	@RequestMapping(value = "/getBenchmarkYear")
	public InvokeResult getBenchmarkYear() {		
		List<Object[]> asyearlist = wordDRGsReportFacade.getBenchmarkYear();
		return InvokeResult.success(asyearlist);	
	}

	/**
	 * 
	 * @Description : 图片的生成
	 * @methodname :saveImg
	 * @author:ShaoZhiYuan
	 * @return InvokeResult
	 * @date :2017年2月20日
	 */
	@ResponseBody
	@RequestMapping(value = "/saveImg")
	public InvokeResult saveImg(@RequestParam String imgData, @RequestParam String imgName) {
		/**
		 * 生成图片部分
		 */
		try {
			String img = imgData.split(",")[1]; // 逗号分隔，逗号后面是base64图片编码
			finalmap.put(imgName, img);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return InvokeResult.success();
	}

	
	/**
	 * 
	 * @Description : 查找生成报告所需数据
	 * @methodname :findReportInfo
	 * @author:ShaoZhiYuan
	 * @return InvokeResult
	 * @date :2017年2月20日
	 */
	@ResponseBody
	@RequestMapping(value="/findReportInfo")
	public InvokeResult findReportInfo(HttpServletRequest request,HttpServletResponse response){
		Map<String,Object> dto=new ParamMap().newMap(request);
		finalmap=new HashMap<>();
		paramMap=new HashMap<>();
		Map<String, List<Map<String, Object>>>  abnormalMap = new HashMap<>();
		String hospCode=dto.get("hospCode")==null?"":dto.get("hospCode").toString();  //院区选择
		String dateFrom=dto.get("dateFrom")==null?"":dto.get("dateFrom").toString();  //起始日期
		String dateTo=dto.get("dateTo")==null?"":dto.get("dateTo").toString();        //终止日期
		String stdId=drgsIndexCalFacade.getStdID(dateFrom,dateTo);   //获取标杆定位id
		String groupScheme=drgsIndexCalFacade.getGroupScheme();    //获取分组方案
		String hospBuildYear=dto.get("hospBuildYear")==null?"--":dto.get("hospBuildYear").toString(); //创建年份
		String hospLevel=dto.get("hospLevel")==null?"--":dto.get("hospLevel").toString().trim();  //医院级别
		String hospType=dto.get("hospType")==null?"综合医院":dto.get("hospType").toString().trim();  //医院类型
		String hospBedNum=dto.get("hospBedNum")==null?"--":Arith.dataFormat(dto.get("hospBedNum").toString(), "2");  //核定床位数
		String hospBedNum_temp=dto.get("hospBedNum")==null?"0":dto.get("hospBedNum").toString();  //核定床位数(计算)
		String hospRealBedNum=dto.get("hospRealBedNum")==null?"--":Arith.dataFormat(dto.get("hospRealBedNum").toString(), "2");  //实际床位数
		String hospCaseNum=dto.get("hospCaseNum")==null?"--":Arith.dataFormat(dto.get("hospCaseNum").toString(), "3"); //年门急诊量
		String hospDocNum=dto.get("hospDocNum")==null?"--":Arith.dataFormat(dto.get("hospDocNum").toString(), "2");    //医师数量
		String hospBedDaysNum=dto.get("hospBedDaysNum")==null?"--":dto.get("hospBedDaysNum").toString();  //开放总床日数
		String mdcCode=dto.get("mdcCode")==null?"":dto.get("mdcCode").toString().trim();     //重点MDC
		String startMonth = Integer.valueOf(dateFrom.substring(5, 7)) + "";// 分析开始月
		String endMonth = Integer.valueOf(dateTo.substring(5, 7)) + ""; // 分析结束月
		String isAbno=(dto.get("isAbno")==null?"":dto.get("isAbno").toString()); //是否为异常数据
		String isComplete=(dto.get("isComplete")==null?"":dto.get("isComplete").toString()); //是否进行数据完整性校验
		GetAbnormity abnorm = new GetAbnormity();// 定义抛出异常类
	
		//根据分组方案获取分组器版本号
		String drgVersion = wordDRGsReportFacade.getDRGversionCode(groupScheme);
		
		paramMap.put("reportDateFrom", dateFrom);
		paramMap.put("reportDateTo", dateTo);
		paramMap.put("drgVersion", drgVersion);
		paramMap.put("stdId", stdId);
		paramMap.put("groupScheme", groupScheme);
		paramMap.put("hospCode", hospCode);
		// 获取医院名称
	    String hospName=dto.get("hospName")==null?"--":dto.get("hospName").toString().trim();
		if(hospName.endsWith("医院")){
			hospName=hospName.substring(0, hospName.length()-2);
		}
		
		//判断有没有数据
		int dataIsNull=wordDRGsReportFacade.findDataIsNull(dateFrom, dateTo,groupScheme,hospCode);
		if(dataIsNull!=0){
			List<Object[]> drgsList = wordDRGsReportFacade.findNewDrgs(dateFrom, dateTo, stdId ,groupScheme,hospCode);
			if (!drgsList.isEmpty()) {
				Map<String, Object> nmap = new HashMap<String, Object>();
				nmap.put("newdrgs", 1);
				nmap.put("drgsList", drgsList);
				return InvokeResult.success(nmap);
			} else {
			/*	监测数据是否完整*/
				List<Object[]> checkedList = wordDRGsReportFacade.findCheckedData(dateFrom, dateTo,hospCode);
				Object[] objch=checkedList.get(0);
				double operlevelRatio=objch[0]==null?0:Double.valueOf(objch[0].toString());
				double opercodeRatio=objch[1]==null?0:Double.valueOf(objch[1].toString());
				double opertypeRatio=objch[2]==null?0:Double.valueOf(objch[2].toString());
				double ditypeRatio=objch[3]==null?0:Double.valueOf(objch[3].toString());
				double dicodeRatio=objch[4]==null?0:Double.valueOf(objch[4].toString());
			
			  if (isComplete.trim().equals("1")&&(operlevelRatio <0.85 ||opercodeRatio<0.85|| opertypeRatio<0.85||ditypeRatio<0.85||dicodeRatio<0.85)) {
					return InvokeResult.failure("请检测您导入的数据中手术编码、手术级别、手术类型、诊断编码、诊断类型是否符合数据规范！");
				}else {
				try {
					Calendar cal = Calendar.getInstance();// 使用日历类
					String year = cal.get(Calendar.YEAR) + "";// 得到年
					String month = (cal.get(Calendar.MONTH) + 1) + "";// 得到月，因为从0开始的，所以要加1
					
					finalmap.put("startMonth", startMonth);
					finalmap.put("endMonth", endMonth);
					finalmap.put("createyear", year);
					finalmap.put("createmonth", month);
					
					//加载医院基础信息
					finalmap.put("hospName", hospName);
					finalmap.put("hospBuildYear", hospBuildYear);
					finalmap.put("hospLevel", hospLevel);
					finalmap.put("hospBedNum", hospBedNum);
					finalmap.put("hospRealBedNum", hospRealBedNum);
					finalmap.put("hospCaseNum", hospCaseNum);
					finalmap.put("hospDocNum", hospDocNum);
					finalmap.put("hospBedDaysNum", hospBedDaysNum);
					
					// 获取科室数量
					int hospdepcnt = wordDRGsReportFacade.findDepCount();
					finalmap.put("hospdepcnt", hospdepcnt);	
					
					//加载年份信息
					String analysisyear = dateFrom.substring(0, 4);// 分析的年份
					String analysisdateTo = dateTo.substring(0, 4);// 分析的年份
					String analysismonthfrom=dateFrom.substring(5, 7); //分析开始的月份
					String analysismonthto=dateTo.substring(5, 7); //分析结束的月份
					finalmap.put("analysisyear", analysisyear);
					if(!analysisyear.equals(analysisdateTo)){
						finalmap.put("analysisnewtime",dateFrom.substring(0, 4)+"年"+dateFrom.substring(5, 7)+"月至"+dateTo.substring(0, 4)+"年"+dateTo.substring(5, 7)+"月" );
					}else if(analysisyear.equals(analysisdateTo)&&analysismonthfrom.equals("01")&&analysismonthto.equals("12")){
						finalmap.put("analysisnewtime",analysisyear+"年");
					}else{
						finalmap.put("analysisnewtime",dateFrom.substring(0, 4)+"年"+dateFrom.substring(5, 7)+"月至"+dateTo.substring(0, 4)+"年"+dateTo.substring(5, 7)+"月" );
					}
					
					// 获取出院病历术，大于60.入组数， 入组率
					Object[] hospBaseQuotaStOne = wordDRGsReportFacade.findSimpHospBaseQuota(paramMap);
					if (hospBaseQuotaStOne.length > 0) {
						finalmap.put("hospoutcasecnt", hospBaseQuotaStOne[0] == null ? "0": Arith.dataFormat(hospBaseQuotaStOne[0].toString(), "2"));// 出院病例数
						finalmap.put("hospoutcasecnt_temp", hospBaseQuotaStOne[0] == null ? "0": Integer.parseInt(hospBaseQuotaStOne[0]+""));// 出院病例数 (未格式化)
						finalmap.put("ingroupcasecnt",hospBaseQuotaStOne[1] == null ? "0" : Arith.dataFormat(hospBaseQuotaStOne[1].toString(), "2"));// 入组数
						finalmap.put("ingroupcasecnt_temp",hospBaseQuotaStOne[1] == null ? "0" : hospBaseQuotaStOne[1].toString());// 入组数 (未格式化)
						finalmap.put("over60casecnt", hospBaseQuotaStOne[2] == null ? "0" :Arith.dataFormat(hospBaseQuotaStOne[2].toString(), "2"));// 大于60
						finalmap.put("over60casecnt_temp", hospBaseQuotaStOne[2] == null ? "0" : hospBaseQuotaStOne[2].toString());// 大于60 (未格式化)
						finalmap.put("ingroupratio", hospBaseQuotaStOne[3] == null ? 0 : hospBaseQuotaStOne[3]);// 入组率
						finalmap.put("notingroupcasecnt", hospBaseQuotaStOne[4] == null ? "0": Arith.dataFormat(hospBaseQuotaStOne[4].toString(), "2"));// 未入组
						finalmap.put("notingroupcasecnt_temp", hospBaseQuotaStOne[4] == null ? "0": hospBaseQuotaStOne[4].toString().trim());// 未入组 (未格式化)
					} else {
						finalmap.put("hospoutcasecnt", 0);// 出院病例数
						finalmap.put("ingroupcasecnt", 0);// 入组数
						finalmap.put("over60casecnt", 0);// 大于60
						finalmap.put("ingroupratio", 0);// 入组率
						finalmap.put("notingroupcasecnt", 0);// 未入组
					}
					
					// 获取本院使用的分组器
				    String drgVer = wordDRGsReportFacade.getDRGversion(paramMap);
					StringBuffer drgVers = new StringBuffer();
					if (!"".equals(drgVer)) {
						Pattern p = Pattern.compile("[0-9]");
						Matcher ver = p.matcher(drgVer);
						while (ver.find()) {
							drgVers.append(ver.group());
						}
					}
					String drgVersionDes = drgVers.toString();
					finalmap.put("drgversion", drgVersionDes);
					
					//根据医院级别和医院类型选择常规指标及部分描述
					String regularStandardType="regularStandard1";
					String regularStandardStrHalf="";
					if(("三级甲等".equals(hospLevel)||"三级乙等".equals(hospLevel)||"三级".equals(hospLevel))&&"综合医院".equals(hospType)){
						regularStandardType="regularStandard1";
						regularStandardStrHalf="三级综合医院的常规统计指标数据";
					}else if(("三级甲等".equals(hospLevel)||"三级乙等".equals(hospLevel)||"三级".equals(hospLevel))&&"中医医院".equals(hospType)){
						regularStandardType="regularStandard2";
						regularStandardStrHalf="三级中医医院和同级综合医院部分常规指标数据";
					}else if(("三级甲等".equals(hospLevel)||"三级乙等".equals(hospLevel)||"三级".equals(hospLevel))&&"专科医院".equals(hospType)){
						regularStandardType="regularStandard3";
						regularStandardStrHalf="三级专科医院和同级综合医院部分常规指标数据";
					}else if(("二级甲等".equals(hospLevel)||"二级乙等".equals(hospLevel)||"二级".equals(hospLevel))&&"综合医院".equals(hospType)){
						regularStandardType="regularStandard4";
						regularStandardStrHalf="二级综合医院的常规统计指标数据";
					}else if(("二级甲等".equals(hospLevel)||"二级乙等".equals(hospLevel)||"二级".equals(hospLevel))&&"中医医院".equals(hospType)){
						regularStandardType="regularStandard5";
						regularStandardStrHalf="二级中医医院和同级综合医院部分常规指标数据";
					}else if(("二级甲等".equals(hospLevel)||"二级乙等".equals(hospLevel)||"二级".equals(hospLevel))&&"专科医院".equals(hospType)){
						regularStandardType="regularStandard6";
						regularStandardStrHalf="二级专科医院和同级综合医院部分常规指标数据";
					}else if(("一级甲等".equals(hospLevel)||"一级乙等".equals(hospLevel)||"一级".equals(hospLevel))&&"综合医院".equals(hospType)){
						regularStandardType="regularStandard7";
						regularStandardStrHalf="一级综合医院的常规统计指标数据";
					}else if(("一级甲等".equals(hospLevel)||"一级乙等".equals(hospLevel)||"一级".equals(hospLevel))&&"中医医院".equals(hospType)){
						regularStandardType="regularStandard8";
						regularStandardStrHalf="一级中医医院和同级综合医院部分常规指标数据";
					}else if(("一级甲等".equals(hospLevel)||"一级乙等".equals(hospLevel)||"一级".equals(hospLevel))&&"专科医院".equals(hospType)){
						regularStandardType="regularStandard9";
						regularStandardStrHalf="一级专科医院和同级综合医院部分常规指标数据";
					}
					//常规指标总描述
					String regularStandardStr="";
					Properties pro = new Properties();
					InputStream inputStream=null;
					try {
						inputStream=WordDRGsReportController.class.getClassLoader().getResourceAsStream("/system.properties");
						pro.load(new InputStreamReader(inputStream, "UTF-8"));
					} catch (UnsupportedEncodingException e) {
						e.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
						errMsg+=e.getMessage();
						finalmap.put("errMsg", errMsg);
					}finally {
						if(inputStream!=null) {
							inputStream.close();
						}
					}
					
					// 从配置文件里读取表格中的对比指标
					String regularStandard = pro.getProperty(regularStandardType);// 获取常规指标
					String staffStandard = pro.getProperty("staffStandard");// 获取参评指标
					if (!"".equals(regularStandard) && !"".equals(staffStandard)) {
						String[] regularStandardArray = regularStandard.split(",");
						for (int o = 0; o < regularStandardArray.length; o++) {
							String regularStandardHospCnt=regularStandardArray[0]==null?"0":regularStandardArray[0].toString();
							regularStandardStr=regularStandardHospCnt+"家"+regularStandardStrHalf;
							finalmap.put("regularStandardStr", regularStandardStr);
							finalmap.put("outcasecntst", regularStandardArray[1]==null?"0":Arith.dataFormat(regularStandardArray[1].toString(), "2"));
							finalmap.put("avgfeest",  regularStandardArray[2]==null?0:Arith.dataFormat(regularStandardArray[2].toString(), "3"));
							finalmap.put("avgdaysst",  regularStandardArray[3]==null?0:regularStandardArray[3]);
							finalmap.put("drugratiost",  regularStandardArray[4]==null?0:regularStandardArray[4]);
							finalmap.put("deadratiost",  regularStandardArray[5]==null?0:regularStandardArray[5]);
						}

						String[] staffStandardArray = staffStandard.split(",");
						for (int o = 0; o < staffStandardArray.length; o++) {
							finalmap.put("ingroupcasecntst",staffStandardArray[0]==null?"0":Arith.dataFormat(staffStandardArray[0].toString(), "2"));
							finalmap.put("cmist", staffStandardArray[1]==null?0:Arith.dataFormat(staffStandardArray[1].toString(), "1"));
							finalmap.put("drgcntst",staffStandardArray[2]==null?"0":Arith.dataFormat(staffStandardArray[2].toString(), "2"));
							finalmap.put("totalweightst",staffStandardArray[3]==null?"0":Arith.dataFormat(staffStandardArray[3].toString(), "3"));
							finalmap.put("begweightst",staffStandardArray[4]==null?0:Arith.dataFormat(staffStandardArray[4].toString(), "1"));
							finalmap.put("timefeest", staffStandardArray[5]==null?0:Arith.dataFormat(staffStandardArray[5].toString(), "1"));
							finalmap.put("efffeest", staffStandardArray[6]==null?0:Arith.dataFormat(staffStandardArray[6].toString(), "1"));
							finalmap.put("risk1rationst", staffStandardArray[7]==null?0:Arith.dataFormat(staffStandardArray[7].toString(), "1"));
						}
					}
					
					// 表格二中出院病例数，次均费用，药占比等
					Object[] hospBaseTable2StOne = wordDRGsReportFacade.findSimpHospBaseTable2(paramMap);
					if (hospBaseTable2StOne.length > 0) {
						finalmap.put("hospavgfee", hospBaseTable2StOne[1] == null ? 0 : hospBaseTable2StOne[1]);
						finalmap.put("hospavgdays", hospBaseTable2StOne[2] == null ? 0 : hospBaseTable2StOne[2]);
						finalmap.put("hospdrugratio", hospBaseTable2StOne[3] == null ? 0 : hospBaseTable2StOne[3]);
						finalmap.put("hospdeadratio",hospBaseTable2StOne[4] == null ? 0 : hospBaseTable2StOne[4]);
					} else {
						finalmap.put("hospavgfee", "--");
						finalmap.put("hospavgdays", "--");
						finalmap.put("hospdrugratio", "--");
						finalmap.put("hospdeadratio", "--");
					}
					
					// 获取cmi，时间消耗指数，费用消耗指数，drg组数,总权重
					Object[] hospobj4 = wordDRGsReportFacade.findSimpHospBaseTable4(paramMap);
					finalmap.put("hospdrgcnt", hospobj4[0]==null?0:hospobj4[0]);
					finalmap.put("hospcmi", hospobj4[1]==null?0:hospobj4[1]);
					finalmap.put("hosptotalweight",  hospobj4[2]==null?0:hospobj4[2]);
					finalmap.put("hospingroupcnt",  hospobj4[3]==null?0:hospobj4[3]);
					finalmap.put("hospeffee",  hospobj4[4]==null?0:hospobj4[4]);
					finalmap.put("hosptimefee",  hospobj4[5]==null?0:hospobj4[5]);
					finalmap.put("deadrisk1ratio",  hospobj4[6]==null?0:hospobj4[6]);
					double bedWeight=0;
					if(hospBedDaysNum.equals("1")){
						finalmap.put("bedWeight", "--");
					}else{
						if(hospBedNum_temp!="0"){
							 bedWeight = Double.valueOf(finalmap.get("hosptotalweight")+"") / (Double.valueOf(hospBedNum_temp));
						}
						finalmap.put("bedWeight", bedWeight);
					}
					
				// ######################第二章开始######################################
					// 获取手术病例
					String caseOperCount = wordDRGsReportFacade.findHospCaseOperationCount(paramMap);
					finalmap.put("caseOperCount_temp", Integer.parseInt(caseOperCount+""));
					finalmap.put("caseOperCount", Arith.dataFormat(caseOperCount+"", "2"));
					String operRation="0";
					if(finalmap.get("hospoutcasecnt_temp")!="0"){
						 operRation = (Arith.mul(Arith.div(Double.valueOf(caseOperCount), Double.valueOf(finalmap.get("hospoutcasecnt_temp") + ""), 4), 100))+"";
					}else{
						operRation="0";
					}
					//手术占比
					finalmap.put("operRation", operRation);
					
					// 获取手术级别
					List<Object[]> oplevelList = wordDRGsReportFacade.findOperCaseByLvel(paramMap);
					String mostlevelname = "--";
					int level1 = 0;
					int level2 = 0;
					int level3 = 0;
					int level4 = 0;
					int leveloth = 0;
					int mostlevelcnt = 0;
					if (oplevelList.size() > 0) {
						for (int i = 0; i < oplevelList.size(); i++) {
							Object[] obj = oplevelList.get(i);
							String level = obj[0] == null ? "--" : (obj[0] + "").trim();
							int levelcnt = obj[1] == null ? 0 : Double.valueOf(obj[1] + "").intValue();
							if (i == 0) {
								if (level.equals("1")) {
									level1 = levelcnt;
									mostlevelcnt = levelcnt;
									mostlevelname = "一级";
								} else if (level.equals("2")) {
									level2 = levelcnt;
									mostlevelcnt = levelcnt;
									mostlevelname = "二级";
								} else if (level.equals("3")) {
									level3 = levelcnt;
									mostlevelcnt = levelcnt;
									mostlevelname = "三级";
								} else if (level.equals("4")) {
									level4 = levelcnt;
									mostlevelcnt = levelcnt;
									mostlevelname = "四级";
								} else {
									leveloth = levelcnt;
									mostlevelcnt = levelcnt;
									mostlevelname = level;
								}
							} else {
								if (level.equals("1")) {
									level1 = levelcnt;
								} else if (level.equals("2")) {
									level2 = levelcnt;
								} else if (level.equals("3")) {
									level3 = levelcnt;
								} else if (level.equals("4")) {
									level4 = levelcnt;
								} else {
									leveloth = levelcnt;
								}
							}
						}
					}
					finalmap.put("mostlevelname", mostlevelname);
					if(caseOperCount!="0"){
						finalmap.put("mostlevelratio", imputedRatio(Double.valueOf(mostlevelcnt),Double.valueOf(caseOperCount)));
					}else{
						finalmap.put("mostlevelratio","0");
					}
					finalmap.put("level1",level1);
					finalmap.put("level2", level2);
					finalmap.put("level3", level3);
					finalmap.put("level4", level4);
					finalmap.put("leveloth", leveloth);
					
					// 表格6数据 
					List<Map<String, Object>> operLevelList = wordDRGsReportFacade.findOperLevelInfo(paramMap);
					finalmap.put("operLevelList", operLevelList);
					
					// 获取主要手术（根据手术编码分组）
					List<Object[]> mainOperListStepTwo = wordDRGsReportFacade.findMainOperList(paramMap);
					StringBuilder sqlstr = new StringBuilder();
					int top20mainopercnt = 0;
					if (mainOperListStepTwo.size() > 0) {
						// 获取主要手术种类数
						int mainoperkindcnt = mainOperListStepTwo.size();
						finalmap.put("mainoperkindcnt",mainoperkindcnt);
						int totalopercnt=0;
						sqlstr.append("( \n");
						for (int i = 0; i < mainoperkindcnt; i++) {
							Object[] obj = mainOperListStepTwo.get(i);
							if (i < 20) {
								// 计算本院前20的手术数量
								top20mainopercnt = top20mainopercnt + Double.valueOf((obj[1] == null ? 0 : obj[1]) + "").intValue();
								// 拼接手术频次前二十的手术编码
								sqlstr.append(" '" + obj[0] + "', \n");
							}
							totalopercnt+=Double.valueOf((obj[1] == null ? 0 : obj[1]) + "").intValue();
						}
						sqlstr.append(" )\n");
						finalmap.put("top20mainopercnt", top20mainopercnt);
						if(totalopercnt!=0){
							finalmap.put("mainopertop20ratio",imputedRatio(Double.valueOf(top20mainopercnt),Double.valueOf(totalopercnt)));
						}else{
							finalmap.put("mainopertop20ratio","0");
						}
					} else {
						finalmap.put("mainoperkindcnt", 0);
						finalmap.put("top20mainopercnt", 0);
						finalmap.put("mainopertop20ratio", 0);
					}
					
					//计算前20的主要手术的病例里哪两个手术最多
					List<Object[]> mainOperLevelMost = wordDRGsReportFacade.findMainOperLevelList(paramMap);
					String theMostHightOperLevel="";
					String theSecondHightOperLevel="";
					if (mainOperLevelMost.size()>0) {
						String theMostLevel="0";
						String theSecondLevel="0";
						theMostLevel=(mainOperLevelMost.get(0))[0]==null?"0":(mainOperLevelMost.get(0))[0].toString().trim();
						//最多的手术级别
						if("1".equals(theMostLevel)){
							theMostHightOperLevel="一级手术";
						}else if("2".equals(theMostLevel)){
							theMostHightOperLevel="二级手术";
						}else if("3".equals(theMostLevel)){
							theMostHightOperLevel="三级手术";
						}else if("4".equals(theMostLevel)){
							theMostHightOperLevel="四级手术";
						}else{
							theMostHightOperLevel="其他(未填写手术级别类)手术";
						}
						if(mainOperLevelMost.size()>1){
							theSecondLevel=(mainOperLevelMost.get(1))[0]==null?"0":(mainOperLevelMost.get(1))[0].toString().trim();
						}
						//第二多的手术级别
						if("1".equals(theSecondLevel)){
							theSecondHightOperLevel="一级手术";
						}else if("2".equals(theSecondLevel)){
							theSecondHightOperLevel="二级手术";
						}else if("3".equals(theSecondLevel)){
							theSecondHightOperLevel="三级手术";
						}else if("4".equals(theSecondLevel)){
							theSecondHightOperLevel="四级手术";
						}else if("5".equals(theSecondLevel)){
							theSecondHightOperLevel="--";
						}else{
							theSecondHightOperLevel="其他(未填写手术级别类)手术";
						}
						finalmap.put("theMostHightOperLevel", theMostHightOperLevel);
						finalmap.put("theSecondHightOperLevel", theSecondHightOperLevel);
					} else {
						finalmap.put("theMostHightOperLevel", "--");
						finalmap.put("theSecondHightOperLevel", "--");
					}
					
					// 频次发生最高前五名手术操作的科室分布
					List<Map<String, Object>> top1OpercodedepMapList = new ArrayList<>();
					List<Map<String, Object>> top2OpercodedepMapList = new ArrayList<>();
					List<Map<String, Object>> top3OpercodedepMapList = new ArrayList<>();
					List<Map<String, Object>> top4OpercodedepMapList = new ArrayList<>();
					List<Map<String, Object>> top5OpercodedepMapList = new ArrayList<>();
					List<Object[]> top5opercode = wordDRGsReportFacade.findTop5OperCode(paramMap);
					if (top5opercode.size() > 0) {
						for (int i = 0; i < top5opercode.size(); i++) {
							Object[] obj = top5opercode.get(i);
							if (i == 0) {
								paramMap.put("operOrder", "1");
								top1OpercodedepMapList = wordDRGsReportFacade.top5OpercodedepListByOperCode(paramMap, obj[0]);
							} else if (i == 1) {
								paramMap.put("operOrder", "2");
								top2OpercodedepMapList = wordDRGsReportFacade.top5OpercodedepListByOperCode(paramMap, obj[0]);
							} else if (i == 2) {
								paramMap.put("operOrder", "3");
								top3OpercodedepMapList = wordDRGsReportFacade.top5OpercodedepListByOperCode(paramMap, obj[0]);
							} else if (i == 3) {
								paramMap.put("operOrder", "4");
								top4OpercodedepMapList = wordDRGsReportFacade.top5OpercodedepListByOperCode(paramMap, obj[0]);
							} else if (i == 4) {
								paramMap.put("operOrder", "5");
								top5OpercodedepMapList = wordDRGsReportFacade.top5OpercodedepListByOperCode(paramMap, obj[0]);
							}
						}
					}
					String depname="--";
					if(!top1OpercodedepMapList.isEmpty()){	
						depname="";
						for (int i=0 ;i<top1OpercodedepMapList.size();i++){
							if (i<3) {
								Map<String, Object> map =top1OpercodedepMapList.get(i);
								 depname += map.get("depname")+"、";
							}
						}
						if (depname.lastIndexOf("、") > 0) {
							depname= depname.substring(0, depname.lastIndexOf("、"))+"";
						}
						if(depname.length()<1){
							finalmap.put("moremostOper", "--");
						}else{
							finalmap.put("moremostOper", depname);
						}
					}else{
						finalmap.put("moremostOper", depname);
					}
					finalmap.put("top1OpercodedepMapList", top1OpercodedepMapList);
					finalmap.put("top2OpercodedepMapList", top2OpercodedepMapList);
					finalmap.put("top3OpercodedepMapList", top3OpercodedepMapList);
					finalmap.put("top4OpercodedepMapList", top4OpercodedepMapList);
					finalmap.put("top5OpercodedepMapList", top5OpercodedepMapList);
					
					// 各级手术前5手术编码，名称，频次，占本级手术的占比
					List<Object[]> mainOperLevelInfoList = wordDRGsReportFacade.findmainOperLevelInfo(paramMap);
					List<Map<String, Object>> mainOperLevel1InfoTop5List = new ArrayList<Map<String, Object>>();
					List<Map<String, Object>> mainOperLevel2InfoTop5List = new ArrayList<Map<String, Object>>();
					List<Map<String, Object>> mainOperLevel3InfoTop5List = new ArrayList<Map<String, Object>>();
					List<Map<String, Object>> mainOperLevel4InfoTop5List = new ArrayList<Map<String, Object>>();
					int totalle1 = 0, totalle2 = 0, totalle3 = 0, totalle4 = 0, totallenull = 0;
					if (mainOperLevelInfoList.size() > 0) {						
						for (int m = 0; m < mainOperLevelInfoList.size(); m++) {
							Object[] obj = mainOperLevelInfoList.get(m);
							String obj0 = obj[0] == null ? "0" : obj[0].toString().trim();
							String  obj1= obj[1] == null ? "0" : obj[1].toString().trim();
							if (obj0.equals("1")) {
								totalle1 = totalle1 + Integer.valueOf(obj1);
							} else if (obj0.equals("2")) {
								totalle2 = totalle2 + Integer.valueOf(obj1);
			
							} else if (obj0.equals("3")) {
								totalle3 = totalle3 + Integer.valueOf(obj1);
	
							} else if (obj0.equals("4")) {
								totalle4 = totalle4 + Integer.valueOf(obj1);

							} else {
								totallenull = totallenull + Integer.valueOf(obj1);
							}
						}
					}
					int le1 = 1, le2 = 1, le3 = 1, le4 = 1;					
					List<Object[]> mainOperLevel1List = wordDRGsReportFacade.findmainOperByLevelInfo(paramMap,"1");	
					if(!mainOperLevel1List.isEmpty()){
						for(Object[] obj:mainOperLevel1List){
							Map<String, Object> map = new HashMap<String, Object>();
							String objOne=obj[0]==null?"--":obj[0].toString().trim();
							String objTwo=obj[1]==null?"--":obj[1].toString().trim();
							if (le1 < 6) {
								map.put("order", le1);
								map.put("level", "一级");
								map.put("opercode", objOne);
								map.put("operation",  objTwo);
								map.put("opercnt", obj[2] ==null?0: Arith.dataFormat(obj[2]+"", "2"));
								if(totalle1!=0){
									map.put("operRatio",imputedRatio(Double.valueOf((obj[2] == null ? 0 : obj[2]) + ""),Double.valueOf(totalle1)));
								}else{
									map.put("operRatio","0");
								}
								mainOperLevel1InfoTop5List.add(map);
								le1++;
							}
						}	
					}
					finalmap.put("mainOperLevel1InfoTop5List", mainOperLevel1InfoTop5List);
					
					List<Object[]> mainOperLevel2List = wordDRGsReportFacade.findmainOperByLevelInfo(paramMap,"2");	
					if(!mainOperLevel2List.isEmpty()){
						for(Object[] obj:mainOperLevel2List){
							Map<String, Object> map = new HashMap<String, Object>();
							String objOne=obj[0]==null?"--":obj[0].toString().trim();
							String objTwo=obj[1]==null?"--":obj[1].toString().trim();
							if (le2 < 6) {
								map.put("order", le2);
								map.put("level", "二级");
								map.put("opercode", objOne);
								map.put("operation",  objTwo);
								map.put("opercnt", obj[2] ==null?0: Arith.dataFormat(obj[2]+"", "2"));
								if(totalle2!=0){
									map.put("operRatio",imputedRatio(Double.valueOf((obj[2] == null ? 0 : obj[2]) + ""),Double.valueOf(totalle2)));
								}else{
									map.put("operRatio","0");
								}
								mainOperLevel2InfoTop5List.add(map);
								le2++;
							}
						}	
					}
					finalmap.put("mainOperLevel2InfoTop5List", mainOperLevel2InfoTop5List);
					
					List<Object[]> mainOperLevel3List = wordDRGsReportFacade.findmainOperByLevelInfo(paramMap,"3");	
					if(!mainOperLevel3List.isEmpty()){
						for(Object[] obj:mainOperLevel3List){
							Map<String, Object> map = new HashMap<String, Object>();
							String objOne=obj[0]==null?"--":obj[0].toString().trim();
							String objTwo=obj[1]==null?"--":obj[1].toString().trim();
							if (le3 < 6) {
								map.put("order", le3);
								map.put("level", "三级");
								map.put("opercode",objOne);
								map.put("operation", objTwo);
								map.put("opercnt", obj[2] ==null?0: Arith.dataFormat(obj[2]+"", "2"));
								if(totalle3!=0){
									map.put("operRatio",imputedRatio(Double.valueOf((obj[2] == null ? 0 : obj[2]) + ""),Double.valueOf(totalle3)));
								}else{
									map.put("operRatio","0");
								}
								mainOperLevel3InfoTop5List.add(map);
								le3++;
							}
						}	
					}
					finalmap.put("mainOperLevel3InfoTop5List", mainOperLevel3InfoTop5List);
					
					List<Object[]> mainOperLevel4List = wordDRGsReportFacade.findmainOperByLevelInfo(paramMap,"4");	
					if(!mainOperLevel4List.isEmpty()){
						for(Object[] obj:mainOperLevel4List){
							Map<String, Object> map = new HashMap<String, Object>();
							String objOne=obj[0]==null?"--":obj[0].toString().trim();
							String objTwo=obj[1]==null?"--":obj[1].toString().trim();
							if (le4 < 6) {
								map.put("order", le4);
								map.put("level", "四级");
								map.put("opercode", objOne);
								map.put("operation", objTwo);
								map.put("opercnt", obj[2] ==null?0: Arith.dataFormat(obj[2]+"", "2"));
								if(totalle4!=0){
									map.put("operRatio",imputedRatio(Double.valueOf((obj[2] == null ? 0 : obj[2]) + ""),Double.valueOf(totalle4)));
								}else{
									map.put("operRatio","0");
								}
								mainOperLevel4InfoTop5List.add(map);
								le4++;
							}
						}	
					}
					finalmap.put("mainOperLevel4InfoTop5List", mainOperLevel4InfoTop5List);
					
					// ##############################第三章开始##################################################################
					// 获取DRG病组,内科组，外科组，操作组
					int totaldrgCnt =0;
					int outdrgcnt = 0;
					int indrgcnt = 0;
					int operdrgcnt = 0;
					int outcasecnt = 0;
					int incasecnt = 0;
					int opercasecnt = 0;
					Boolean hospDRGsListflag=true;
					List<Object[]> hospDRGsList = wordDRGsReportFacade.findHospDRGsInfo(paramMap);
					
						for(Object[] hospDRGsInfoStep:hospDRGsList){
							while(hospDRGsListflag){
						     totaldrgCnt=Integer.parseInt(hospDRGsInfoStep[0]==null?"0":hospDRGsInfoStep[0].toString().trim());
							 outdrgcnt = Integer.parseInt(hospDRGsInfoStep[1]==null?"0":hospDRGsInfoStep[1].toString().trim());
							 indrgcnt = Integer.parseInt(hospDRGsInfoStep[2]==null?"0":hospDRGsInfoStep[2].toString().trim());
							 operdrgcnt = Integer.parseInt(hospDRGsInfoStep[3]==null?"0":hospDRGsInfoStep[3].toString().trim());
							 outcasecnt = Integer.parseInt(hospDRGsInfoStep[4]==null?"0":hospDRGsInfoStep[4].toString().trim());
							 incasecnt = Integer.parseInt(hospDRGsInfoStep[5]==null?"0":hospDRGsInfoStep[5].toString().trim());
							 opercasecnt = Integer.parseInt(hospDRGsInfoStep[6]==null?"0":hospDRGsInfoStep[6].toString().trim());
							 hospDRGsListflag=false;
							}
					}
			
					finalmap.put("totaldrgcnt", totaldrgCnt);
					finalmap.put("outdrgcnt", outdrgcnt);
					finalmap.put("indrgcnt", indrgcnt);
					finalmap.put("operdrgcnt", operdrgcnt);
					finalmap.put("outcasecnt", outcasecnt);
					finalmap.put("incasecnt", incasecnt);
					finalmap.put("opercasecnt", opercasecnt);
					
					int DRGsType1Num = 0;
					int DRGsType3Num = 0;
					int DRGsType5Num = 0;
					int DRGsType9Num = 0;

					int CaseType1Num = 0;
					int CaseType3Num = 0;
					int CaseType5Num = 0;
					int CaseType9Num = 0;
					Boolean hospDRGsInfoListflag=true;
					List<Object[]> hospDRGsInfoList = wordDRGsReportFacade.findPersonCnt(paramMap);
					
						for(Object[] hospDRGsInfoStep:hospDRGsInfoList){
							while(hospDRGsInfoListflag){
								DRGsType1Num=Integer.parseInt(hospDRGsInfoStep[0]==null?"0":hospDRGsInfoStep[0].toString().trim());
								DRGsType3Num = Integer.parseInt(hospDRGsInfoStep[1]==null?"0":hospDRGsInfoStep[1].toString().trim());
								DRGsType5Num = Integer.parseInt(hospDRGsInfoStep[2]==null?"0":hospDRGsInfoStep[2].toString().trim());
								CaseType1Num = Integer.parseInt(hospDRGsInfoStep[3]==null?"0":hospDRGsInfoStep[3].toString().trim());
								CaseType3Num = Integer.parseInt(hospDRGsInfoStep[4]==null?"0":hospDRGsInfoStep[4].toString().trim());
								CaseType5Num = Integer.parseInt(hospDRGsInfoStep[5]==null?"0":hospDRGsInfoStep[5].toString().trim());
							    hospDRGsInfoListflag=false;
							}
					}
					DRGsType9Num = totaldrgCnt - DRGsType1Num - DRGsType3Num - DRGsType5Num ;
					finalmap.put("DRGsType1Num", DRGsType1Num);
					finalmap.put("DRGsType3Num", DRGsType3Num);
					finalmap.put("DRGsType5Num", DRGsType5Num);
					finalmap.put("DRGsType9Num", DRGsType9Num);
		      		if (finalmap.get("ingroupcasecnt") != null) {
						CaseType9Num = Double.valueOf(finalmap.get("ingroupcasecnt_temp") + "").intValue() - CaseType1Num - CaseType3Num - CaseType5Num ;
					} else {
						CaseType9Num = 0;
					}
					finalmap.put("CaseType1Num", CaseType1Num);
					finalmap.put("CaseType3Num", CaseType3Num);
					finalmap.put("CaseType5Num", CaseType5Num);
					finalmap.put("CaseType9Num", CaseType9Num);
					
					//获取当前时间段内的科室组数量
					int hospNowDepCnt=wordDRGsReportFacade.findHospNowDepCnt(paramMap);
					finalmap.put("hospNowDepCnt", hospNowDepCnt);
					
					//科室cmi和权重
					List<Map<String, Object>> depWeightAndCMIList = wordDRGsReportFacade.findDepWeightAndCMI(paramMap);
					abnormalMap = new HashMap<String, List<Map<String, Object>>>();
					List<Map<String, Object>> depnormalWeightAndCMIList = new ArrayList<Map<String, Object>>();
					//压入不正常的数据
					String depCWAbnormal="";
					if(isAbno=="1"){
						abnormalMap = abnorm.getAbnormalDataMap(depWeightAndCMIList, "weight", "cmi");//计算是否有异常数据
						List<Map<String, Object>> depAbnormalWeightAndCMIList = abnormalMap.get("abnorMapList");// 异常数据
						depnormalWeightAndCMIList = abnormalMap.get("norMapList");// 参与计算数据
						StringBuffer depCmiWeightAbnormal = new StringBuffer();				
						for (Map<String, Object> map : depAbnormalWeightAndCMIList) {
							Double weight = Double.valueOf(String.valueOf(map.get("weight") == null ? 0 : map.get("weight")));
							Double cmi = Double.valueOf(String.valueOf(map.get("cmi") == null ? 0 : map.get("cmi")));
							depCmiWeightAbnormal.append(map.get("depname") + "(" + cmi + "," + weight + ")、");
						}
						if (depCmiWeightAbnormal.lastIndexOf("、") > 0) {
							depCWAbnormal= depCmiWeightAbnormal.substring(0, depCmiWeightAbnormal.lastIndexOf("、"))+"";
							finalmap.put("depCWAbnormal","其中"+depCWAbnormal+"数据作为特异数据，因为会影响图形展现效果，未显示在下图中。");
						}else{
							finalmap.put("depCWAbnormal","--");
						}
					}else{
						depnormalWeightAndCMIList=depWeightAndCMIList;
						finalmap.put("depCWAbnormal",depCWAbnormal+"--");
					}	
					Double depmiddleWeight=imputedMiddleWeight(depnormalWeightAndCMIList);
					Double depmiddleCmi=imputedMiddleCmi(depnormalWeightAndCMIList);
					
					//高难度高产出的科室数据
					String  highCMIandhighWeightStr="";
					//低难度低产出的科室数据
					String  lowCMIandlowWeightStr="";
					int highCMIandhighWeightCnt=0; 
					int lowCMIandlowWeightCnt=0;
					//将所需的科室数据拼接成字符串
					for (Map<String, Object> map : depnormalWeightAndCMIList) {
						Double weight = Double.valueOf(String.valueOf(map.get("weight") == null ? 0 : map.get("weight")));
						Double cmi = Double.valueOf(String.valueOf(map.get("cmi") == null ? 0 : map.get("cmi")));
					    String depName=map.get("depname") == null ? "--" : map.get("depname")+"";
						if (weight > depmiddleWeight && cmi > depmiddleCmi) {
							highCMIandhighWeightStr+=depName+"("+cmi.toString()+", "+Arith.dataFormat(weight+"", "3")+")、";
							highCMIandhighWeightCnt++;
						}  else if (weight <= depmiddleWeight && cmi <= depmiddleCmi) {
							lowCMIandlowWeightStr+=depName+"("+cmi.toString()+", "+Arith.dataFormat(weight+"", "3")+")、";
							lowCMIandlowWeightCnt++;
						} 
					}
                   if(highCMIandhighWeightStr.length()>1){
                		highCMIandhighWeightStr=highCMIandhighWeightStr.substring(0, highCMIandhighWeightStr.length()-1);
                   }
                   if(lowCMIandlowWeightStr.length()>1){
                	    lowCMIandlowWeightStr=lowCMIandlowWeightStr.substring(0, lowCMIandlowWeightStr.length()-1);
                   }
                   //计算总数
                   finalmap.put("highCMIandhighWeightCnt",highCMIandhighWeightCnt);
                   finalmap.put("lowCMIandlowWeightCnt",lowCMIandlowWeightCnt);
                   if(highCMIandhighWeightStr.length()<1){
                	   finalmap.put("highCMIandhighWeightStr","--");
                   }else{
                	   finalmap.put("highCMIandhighWeightStr",highCMIandhighWeightStr);
                   }
                   if(lowCMIandlowWeightStr.length()<1){
                	   finalmap.put("lowCMIandlowWeightStr","--");
                   }else{
                	   finalmap.put("lowCMIandlowWeightStr",lowCMIandlowWeightStr);
                   }
					finalmap.put("depmiddleWeight", depmiddleWeight);
					finalmap.put("depmiddleCmi", depmiddleCmi);	
					finalmap.put("depnormalWeightAndCMIList", depnormalWeightAndCMIList);	
					
					// 获取科室时间费用消耗指数
					List<Object[]> efficiencyDepInfoList = wordDRGsReportFacade.findEfficiencyDepInfoList(paramMap);
					List<Map<String, Object>> depFeeAndTimeEffMapList = new ArrayList<Map<String, Object>>();
					StringBuffer depTimeFeeAbnormal = new StringBuffer();
					for (Object[] depInfo : efficiencyDepInfoList) {
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("depCode", depInfo[0]==null?"--":depInfo[0].toString().trim());
						map.put("depName", depInfo[1]==null?"--":depInfo[1].toString().trim());
						map.put("feeEff", Arith.round(Double.parseDouble(depInfo[2] == null ? "0" : depInfo[2].toString()), 2));
						map.put("timeEff", Arith.round(Double.parseDouble(depInfo[3] == null ? "0" : depInfo[3].toString()), 2));
						depFeeAndTimeEffMapList.add(map);
					}
					if(isAbno=="1"){
						// 检测时间费用消耗指数异常数据
						abnormalMap = new HashMap<String, List<Map<String, Object>>>();
						abnormalMap = abnorm.getAbnormalDataMap(depFeeAndTimeEffMapList, "feeEff", "timeEff");
						List<Map<String, Object>> depAbnormalTimeFeeList = abnormalMap.get("abnorMapList");// 异常数据
						List<Map<String, Object>> depnormalTimeFeeList = abnormalMap.get("norMapList");// 参与计算数据
						depFeeAndTimeEffMapList=depnormalTimeFeeList;
						for (Map<String, Object> map : depAbnormalTimeFeeList) {
							Double feeEff = Double.valueOf(String.valueOf(map.get("feeEff") == null ? 0 : map.get("feeEff")));
							Double timeEff = Double.valueOf(String.valueOf(map.get("timeEff") == null ? 0 : map.get("timeEff")));
							depTimeFeeAbnormal.append(map.get("depName") + "(" + timeEff + "," + feeEff + ")、");
						}
						if (depTimeFeeAbnormal.lastIndexOf("、") > 0) {
							depCWAbnormal= depTimeFeeAbnormal.substring(0, depTimeFeeAbnormal.lastIndexOf("、"))+"";
							finalmap.put("depTimeFeeAbnormal","其中"+depCWAbnormal+"数据作为特异数据，因为会影响图形展现效果，未显示在下图中。");
						}else{
							finalmap.put("depTimeFeeAbnormal","--");
						}
					}else{
						finalmap.put("depTimeFeeAbnormal","--");
					}
					String depFeeEffAndTimeEffQuadrant1 = "";
					String depFeeEffAndTimeEffQuadrant2 = "";
					//描述哪个象限最多
					String depTimeFeeDescStr="";
					//计算总数
					int   depFeeEffAndTimeEffQuadrant1Cnt=0;
					int   depFeeEffAndTimeEffQuadrant2Cnt=0;
					int   depFeeEffAndTimeEffQuadrant3Cnt=0;
					int   depFeeEffAndTimeEffQuadrant4Cnt=0;
					for (Map<String, Object> map : depFeeAndTimeEffMapList) {
						Double fee = Double.valueOf(String.valueOf(map.get("feeEff") == null ? 0 : map.get("feeEff")));
						Double time = Double.valueOf(String.valueOf(map.get("timeEff") == null ? 0 : map.get("timeEff")));
						String depName=map.get("depName") == null ? "" : map.get("depName")+"";
						if (fee <=1 && time <= 1) {
							depFeeEffAndTimeEffQuadrant1+=depName+"(" + time + ", " + fee + ")、";
							//第三象限
							depFeeEffAndTimeEffQuadrant1Cnt++;
						}  else if (fee > 1 && time > 1) {
							depFeeEffAndTimeEffQuadrant2+=depName+"(" + time + ", " + fee + ")、";
							//第一象限
							depFeeEffAndTimeEffQuadrant2Cnt++;
						} else if(fee <=1 && time > 1){
							//第四象限
							depFeeEffAndTimeEffQuadrant3Cnt++;
						} else if(fee > 1 && time <= 1){
							//第二象限
							depFeeEffAndTimeEffQuadrant4Cnt++;
						}
					}
					if(depFeeEffAndTimeEffQuadrant1.length()>1){
						depFeeEffAndTimeEffQuadrant1=depFeeEffAndTimeEffQuadrant1.substring(0, depFeeEffAndTimeEffQuadrant1.length()-1);
					}
					if(depFeeEffAndTimeEffQuadrant2.length()>1){
						depFeeEffAndTimeEffQuadrant2=depFeeEffAndTimeEffQuadrant2.substring(0, depFeeEffAndTimeEffQuadrant2.length()-1);	
					}
					//选出哪个象限的科室最多
					int[] depFeeEffAndTimeEff={depFeeEffAndTimeEffQuadrant1Cnt,depFeeEffAndTimeEffQuadrant2Cnt,depFeeEffAndTimeEffQuadrant3Cnt,depFeeEffAndTimeEffQuadrant4Cnt};
					int depFeeEffAndTimeTemp=0;
					for(int i=0; i<3; i++){
						for(int j=0; j<3-i; j++){
							if(depFeeEffAndTimeEff[j]<depFeeEffAndTimeEff[j+1]){
								depFeeEffAndTimeTemp=depFeeEffAndTimeEff[j];
								depFeeEffAndTimeEff[j]=depFeeEffAndTimeEff[j+1];
								depFeeEffAndTimeEff[j+1]=depFeeEffAndTimeTemp;
							}
						}
					}
					if(depFeeEffAndTimeEff[0]==depFeeEffAndTimeEff[1]){
						finalmap.put("depTimeFeeDescStr", "");
					}else{
						if(depFeeEffAndTimeEff[0]==depFeeEffAndTimeEffQuadrant1Cnt){
							finalmap.put("depTimeFeeDescStr", "集中分布在第三象限中的科室数占比最高，即大部分科室费用和平均住院日均低于同行业水平，再次说明本院对科室的资源效率监管做的较好。");
						}else if(depFeeEffAndTimeEff[0]==depFeeEffAndTimeEffQuadrant2Cnt){
							finalmap.put("depTimeFeeDescStr", "集中分布在第一象限中的科室数占比最高，即大部分科室费用和平均住院日均高于同行业水平，再次说明本院对科室的资源效率监管还有较大的提升空间。");
						}else if(depFeeEffAndTimeEff[0]==depFeeEffAndTimeEffQuadrant3Cnt){
							finalmap.put("depTimeFeeDescStr", "集中分布在第四象限中的科室数占比最高，即大部分科室时间消耗高于同行业水平，再次说明本院对科室的资源效率监管还有较大的提升空间。");
						}else if(depFeeEffAndTimeEff[0]==depFeeEffAndTimeEffQuadrant4Cnt){
							finalmap.put("depTimeFeeDescStr", "集中分布在第二象限中的科室数占比最高，即大部分科室费用消耗高于同行业水平，再次说明本院对科室的资源效率监管还有较大的提升空间。");
						}
					}
					
					finalmap.put("depFeeAndTimeEffMapList", depFeeAndTimeEffMapList);
					finalmap.put("depFeeEffAndTimeEffQuadrant1Cnt", depFeeEffAndTimeEffQuadrant1Cnt);
					finalmap.put("depFeeEffAndTimeEffQuadrant2Cnt", depFeeEffAndTimeEffQuadrant2Cnt);
					if(depFeeEffAndTimeEffQuadrant1.length()<1){
						finalmap.put("depFeeEffAndTimeEffQuadrant1","--");
					}else{
						finalmap.put("depFeeEffAndTimeEffQuadrant1",depFeeEffAndTimeEffQuadrant1 );
					}
					if(depFeeEffAndTimeEffQuadrant1.length()<1){
						finalmap.put("depFeeEffAndTimeEffQuadrant2","--");
					}else{
						finalmap.put("depFeeEffAndTimeEffQuadrant2",depFeeEffAndTimeEffQuadrant2 );
					}
					
					// 获取全院低风险死亡率
					String hospCaseRisk1DeadCnt = wordDRGsReportFacade.findHospCaseRisk1Cnt(paramMap);
					finalmap.put("hospCaseRisk1DeadCnto",Arith.dataFormat(hospCaseRisk1DeadCnt, "2"));
					
					// 获取低风险死亡情况科室信息
					List<Object[]> depDeaRisk1List = wordDRGsReportFacade.findQualityDepTableByRisk1List(paramMap);
					String depDeaRisk1Most="";
					if (!depDeaRisk1List.isEmpty()) {
						for (Object[] obj : depDeaRisk1List) {
							String depDeaRisk1Mostdep=obj[0]==null?"--":obj[0]+"";
							String depDeaRisk1MostCnt=obj[2]==null?"0":obj[2]+"";
							String depDeaRisk1Mostariot=obj[3]==null?"0":Arith.dataFormat(obj[3]+"", "1");
							depDeaRisk1Most+=depDeaRisk1Mostdep+"("+depDeaRisk1MostCnt+"例, "+depDeaRisk1Mostariot+"%)、";
						}
					}
					if(depDeaRisk1Most.length()>1){
					depDeaRisk1Most=depDeaRisk1Most.substring(0, depDeaRisk1Most.length()-1);
					}
					
					if(depDeaRisk1Most.length()<=1){
						finalmap.put("depDeaRisk1Most", "--");
					}else{
						finalmap.put("depDeaRisk1Most", "，出现低风险组死亡病例的科室按照低风险组死亡病例数由高至低排列，依次为"+depDeaRisk1Most);
					}
					
					
					// 获取全院中低风险死亡率
					String hospCaseRisk2DeadCnt = wordDRGsReportFacade.findHospCaseRisk2Cnt(paramMap);
					finalmap.put("hospCaseRisk2DeadCnto",Arith.dataFormat(hospCaseRisk2DeadCnt, "2"));
					
					// 获取中低风险死亡情况科室信息
					List<Object[]> depDeaRisk2List = wordDRGsReportFacade.findQualityDepTableByRisk2List(paramMap);
					String depDeaRisk2Most="";
					if (!depDeaRisk2List.isEmpty()) {
						for (Object[] obj : depDeaRisk2List) {
							String depDeaRisk2Mostdep=obj[0]==null?"--":obj[0]+"";
							String depDeaRisk2MostCnt=obj[2]==null?"--":obj[2]+"";
							String depDeaRisk2Mostariot=obj[3]==null?"0":Arith.dataFormat(obj[3]+"", "1");
							depDeaRisk2Most+=depDeaRisk2Mostdep+"("+depDeaRisk2MostCnt+"例, "+depDeaRisk2Mostariot+"%)、";
						}
					} 
					if(depDeaRisk2Most.length()>1){
						depDeaRisk2Most=depDeaRisk2Most.substring(0, depDeaRisk2Most.length()-1);
					}
				
					if(depDeaRisk2Most.length()<=1){
						finalmap.put("depDeaRisk2Most", "--");
					}else{
						finalmap.put("depDeaRisk2Most", "，出现中低风险组死亡病例的科室按照中低风险组死亡病例数由高至低排列，依次为"+depDeaRisk2Most);
					}
					
					//mdc总个数
					int mdcCnt=wordDRGsReportFacade.findMdcCnt(paramMap);
					finalmap.put("mdcCnt", mdcCnt);
					
				    //缺失的mdc专业
					List<Object[]>  oldLostMDCList=wordDRGsReportFacade.findOldLostMDCList(paramMap);
					String lostMDCList="";
					if(!oldLostMDCList.isEmpty()){
						for(Object[] obj:oldLostMDCList){
							String lostMDCListCode=obj[0]==null?"--":obj[0]+"";
							String lostMDCListDesc=obj[1]==null?"--":obj[1]+"";
							lostMDCList+=lostMDCListCode+"("+lostMDCListDesc+")、";
						}
					}
					if(mdcCnt==26){
						finalmap.put("lostMDCList", "不存在专业缺失");
					}else{
						lostMDCList=lostMDCList.substring(0, lostMDCList.length()-1);
						finalmap.put("lostMDCList", "存在专业缺失。缺失的MDC专业为"+lostMDCList);
					}
					
					//DRGs病组覆盖率最高的前五个MDC专业
					List<Object[]>  oldHighRiskAboveMDCList=wordDRGsReportFacade.findOldHighRiskAboveMDCList(paramMap);
					String highRiskAboveMDCList="";
					if(!oldHighRiskAboveMDCList.isEmpty()){
						for(Object[] obj:oldHighRiskAboveMDCList){
							String highRiskAboveMDCListCode=obj[0]==null?"--":obj[0]+"";
							String highRiskAboveMDCListDesc=obj[1]==null?"--":obj[1]+"";
							String highRiskAboveMDCListRate=obj[2]==null?"0":Arith.dataFormat(obj[2]+"", "1");
							highRiskAboveMDCList+=highRiskAboveMDCListCode+"-"+highRiskAboveMDCListDesc+"("+highRiskAboveMDCListRate+"%)、";
						}
					}
					if(highRiskAboveMDCList.length()>1){
					     highRiskAboveMDCList=highRiskAboveMDCList.substring(0, highRiskAboveMDCList.length()-1);
					}
					if(highRiskAboveMDCList.length()<1){
						 finalmap.put("highRiskAboveMDCList", "--");
					}else{
						 finalmap.put("highRiskAboveMDCList", highRiskAboveMDCList);
					}
                    
            		//mdc cmi和权重
    				String mdcCW1 = "";
    				String mdcCW2 = "";
    				List<Object[]> mdcCWList = wordDRGsReportFacade.findMdcCW(paramMap);
    				List<Map<String, Object>> mdcnormalCWIMapList = new ArrayList<Map<String, Object>>();
    				abnormalMap = new HashMap<String, List<Map<String, Object>>>();
    		     	if (!mdcCWList.isEmpty()) {
    					for (Object[] mw : mdcCWList) {
    						Map<String, Object> map = new HashMap<String, Object>();
    						map.put("mdc", mw[0]==null?"--":mw[0]+"");
    						map.put("mdcdesc", mw[1]==null?"--":mw[1]+"");
    						map.put("cmi", Arith.round(Double.parseDouble(mw[2] == null ? "0" : mw[2].toString()), 2));
    						map.put("weight", Arith.round(Double.parseDouble(mw[3] == null ? "0" : mw[3].toString()), 2));
    						mdcnormalCWIMapList.add(map);
    					}
    				}
    				Double mdcmiddleWeight=imputedMiddleWeight(mdcnormalCWIMapList);
    				Double mdcmiddleCmi=imputedMiddleCmi(mdcnormalCWIMapList);
    				//计算总数
    				int highCMIAndHighWeightMDCCnt=0;
    				int lowCMIAndlowWeightMDCCnt=0;
    				for (Map<String, Object> map : mdcnormalCWIMapList) {
    					String mdc=map.get("mdc")==null?"--":map.get("mdc")+"";
    					String mdcdesc=map.get("mdcdesc")==null?"--":map.get("mdcdesc")+"";
    					Double weight = Double.valueOf(String.valueOf(map.get("weight") == null ? 0 : map.get("weight")));
    					Double cmi = Double.valueOf(String.valueOf(map.get("cmi") == null ? 0 : map.get("cmi")));
    					if (weight > mdcmiddleWeight && cmi > mdcmiddleCmi) {
    						mdcCW1+=mdc+"-" +mdcdesc+ "(" + cmi + ", " + Arith.dataFormat(weight+"", "3") + ")、";
    						highCMIAndHighWeightMDCCnt++;
    					} else if (weight <= mdcmiddleWeight && cmi <= mdcmiddleCmi) {
    						mdcCW2+=mdc+"-" +mdcdesc+ "(" + cmi + ", " + Arith.dataFormat(weight+"", "3") + ")、";
    						lowCMIAndlowWeightMDCCnt++;
    					} 
    				}
    				if(mdcCW1.length()>1){
    					mdcCW1=mdcCW1.substring(0, mdcCW1.length()-1);
    				}
    				finalmap.put("highCMIAndHighWeightMDCCnt", highCMIAndHighWeightMDCCnt);
    				finalmap.put("lowCMIAndlowWeightMDCCnt", lowCMIAndlowWeightMDCCnt);
    				if(mdcCW1.length()<1){
    					finalmap.put("highCMIAndHighWeightMDCList", "--");
    				}else{
    					finalmap.put("highCMIAndHighWeightMDCList", mdcCW1);
    				}
    				
    				if(mdcCW2.length()>1){
    					mdcCW2=mdcCW2.substring(0, mdcCW2.length()-1);
    				}
    				
    				if(mdcCW2.length()<1){
    					finalmap.put("lowCMIAndlowWeightMDCList", "--");
    				}else{
    					finalmap.put("lowCMIAndlowWeightMDCList", mdcCW2);
    				}
    				
    				
					// MDC--费用时间消耗指数
    				List<Object[]> mdcFTList = wordDRGsReportFacade.findFeeAndTimeEff(paramMap);
					String mdcFeeET1 = "";
					String mdcFeeET2 = "";
					//计算总数
					int mdcFeeET1Cnt=0;
					int mdcFeeET2Cnt=0;
				    if(!mdcFTList.isEmpty()){
				    	for (Object[] obj : mdcFTList) {
				    		String mdc=obj[0]==null?"--":obj[0]+"";
	    					String mdcdesc=obj[1]==null?"--":obj[1]+"";
							Double fee = Double.valueOf(String.valueOf(obj[2] == null ? 0 : obj[2]+""));
							Double time = Double.valueOf(String.valueOf(obj[3]== null ? 0 : obj[3]+""));
							if (fee <=1 && time <= 1) {
								mdcFeeET1+=mdc+"-" +mdcdesc+ "(" + time + ", " + fee + ")、";
								mdcFeeET1Cnt++;
							} else if (fee > 1 && time > 1) {
								mdcFeeET2+=mdc+"-" +mdcdesc+ "(" + time + ", " + fee + ")、";
								mdcFeeET2Cnt++;
							}
						}
				    }
				   if(mdcFeeET1.length()>1){
					   mdcFeeET1=mdcFeeET1.substring(0, mdcFeeET1.length()-1);
				   }
				   if(mdcFeeET2.length()>1){
					   mdcFeeET2=mdcFeeET2.substring(0, mdcFeeET2.length()-1);
				   }
				   finalmap.put("mdcFeeET1Cnt", mdcFeeET1Cnt);
				   finalmap.put("mdcFeeET2Cnt", mdcFeeET2Cnt);
				   if(mdcFeeET1.length()<1){
					   finalmap.put("mdcFeeET1", "--");
				   }else{
					   finalmap.put("mdcFeeET1", mdcFeeET1);
				   }
				   if(mdcFeeET2.length()<1){
					   finalmap.put("mdcFeeET2", "--");
				   }else{
					   finalmap.put("mdcFeeET2", mdcFeeET2);
				   }
			
			   	    //mdc低风险
					List<Object[]> mdcFTRisk1List = wordDRGsReportFacade.findmdcFTRisk1List(paramMap);
					String mdcFTRisk1MapList="";
					if(!mdcFTRisk1List.isEmpty()){
						for(Object[] obj:mdcFTRisk1List){
							String mdc=obj[0]==null?"--":obj[0]+"";
	    					String mdcdesc=obj[1]==null?"--":obj[1]+"";
	    					String cnt=obj[2]==null?"0":obj[2]+"";
	    					String rate=obj[3]==null?"0.00":Arith.dataFormat(obj[3]+"", "1");
	    					mdcFTRisk1MapList+=mdc+"-" +mdcdesc+ "(" + cnt + "例, " + rate + "%)、";
						}
					}
					if(mdcFTRisk1MapList.length()>1){
						mdcFTRisk1MapList=mdcFTRisk1MapList.substring(0, mdcFTRisk1MapList.length()-1);
					 }
					
					if(mdcFTRisk1MapList.length()<=1){
						finalmap.put("mdcFTRisk1MapList","--");
					}else{
						finalmap.put("mdcFTRisk1MapList", "，出现低风险组死亡病例的MDC专业按照低风险组死亡病例数由高至低排列，依次为"+mdcFTRisk1MapList);
					}
					
					//mdc中低风险
					List<Object[]> mdcFTRisk2List = wordDRGsReportFacade.findmdcFTRisk2List(paramMap);
					String mdcFTRisk2MapList="";
					if(!mdcFTRisk2List.isEmpty()){
						for(Object[] obj:mdcFTRisk2List){
							String mdc=obj[0]==null?"--":obj[0]+"";
	    					String mdcdesc=obj[1]==null?"--":obj[1]+"";
	    					String cnt=obj[2]==null?"0":obj[2]+"";
	    					String rate=obj[3]==null?"0.00":Arith.dataFormat(obj[3]+"", "1");
	    					mdcFTRisk2MapList+=mdc+"-" +mdcdesc+ "(" + cnt + "例, " + rate + "%)、";
						}
					}
					if(mdcFTRisk2MapList.length()>1){
						mdcFTRisk2MapList=mdcFTRisk2MapList.substring(0, mdcFTRisk2MapList.length()-1);
					 }
					
					if(mdcFTRisk2MapList.length()<=1){
						finalmap.put("mdcFTRisk2MapList", "--");
					}else{
						finalmap.put("mdcFTRisk2MapList", "，出现中低风险组死亡病例的MDC专业按照中低风险组死亡病例数由高至低排列，依次为"+mdcFTRisk2MapList);
					}
					
				// ##############################第四章开始##################################################################		
                    
			    //一二级手术例数最多的前十名医师
				List<Object[]>	oldDocOper1List = wordDRGsReportFacade.findDocOper1List(paramMap);
				List<Map<String, Object>> docOper1List = new ArrayList<Map<String, Object>>();
				if(!oldDocOper1List.isEmpty()){
					int i=1;
					for(Object[] obj:oldDocOper1List){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("doc",obj[0]==null?"--":obj[0]+"");
						map.put("dep",obj[1]==null?"--":obj[1]+"" );
						map.put("allcnt",obj[2]==null?"0":Arith.dataFormat(obj[2]+"", "2"));
						map.put("sumcnt",obj[3]==null?"0":Arith.dataFormat(obj[3]+"", "2"));
						map.put("rate",obj[4]==null?"0":Arith.dataFormat(obj[4]+"", "1"));
						map.put("incnt",obj[5]==null?"0":Arith.dataFormat(obj[5]+"", "2"));
						map.put("cmi",obj[6]==null?"0":Arith.dataFormat(obj[6]+"", "1"));
						docOper1List.add(map);
						i++;
					}
				}	
			   finalmap.put("docOper1List", docOper1List);		
					
				//三四级手术例数最多的前十名医师	
				List<Object[]>	oldDocOper2List = wordDRGsReportFacade.findDocOper2List(paramMap);
				List<Map<String, Object>> docOper2List = new ArrayList<Map<String, Object>>();
				if(!oldDocOper2List.isEmpty()){
					int i=1;
					for(Object[] obj:oldDocOper2List){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("doc",obj[0]==null?"--":obj[0]+"");
						map.put("dep",obj[1]==null?"--":obj[1]+"" );
						map.put("allcnt",obj[2]==null?"0":Arith.dataFormat(obj[2]+"", "2"));
						map.put("sumcnt",obj[3]==null?"0":Arith.dataFormat(obj[3]+"", "2"));
						map.put("rate",obj[4]==null?"0":Arith.dataFormat(obj[4]+"", "1"));
						map.put("incnt",obj[5]==null?"0":Arith.dataFormat(obj[5]+"", "2"));
						map.put("cmi",obj[6]==null?"0":Arith.dataFormat(obj[6]+"", "1"));
						docOper2List.add(map);
						i++;
					}
				}	
			   finalmap.put("docOper2List", docOper2List);					
				//************************第五章开始*****************************
				//获取重点MDC
				mdcCode = mdcCode.replaceAll("\\s*", "");// 去除空格
			 String mdccodeStr="";
			if (mdcCode.length() > 4) {
					String[] mdc = mdcCode.split("\\|\\|");
					if (mdc.length > 1) {
						StringBuffer mdcs = new StringBuffer();
						for (int x = 0; x < mdc.length; x++) {
							mdcs.append("'" + mdc[x] + "',");
						}
						if(mdcs.length()>0){
							mdccodeStr=mdcs.substring(0, mdcs.lastIndexOf(","))+"";
						}
					}
				} else {
					mdccodeStr="'" + mdcCode + "'";
				}
			paramMap.put("mdcCode",mdccodeStr);
			List<Object[]>  mdcdescList = wordDRGsReportFacade.findMdcDesc(paramMap);
			String mdcStr="";
			if(mdcdescList.size()>1){
				for(Object[] obj:mdcdescList){
					mdcStr+=obj[0]+"("+obj[1]+")、";
				}
			}else{
				if(!mdcdescList.isEmpty()){
					for(Object[] obj:mdcdescList){
						mdcStr+=obj[0]+"("+obj[1]+")、";
					}
				}
			}
			if(mdcStr.length()<1){
				finalmap.put("mdcStr", "--");
			}else{
				mdcStr=mdcStr.substring(0, mdcStr.length()-1);
				finalmap.put("mdcStr", mdcStr);
			}
			
			int  mdcCaseCnt = wordDRGsReportFacade.findMdcCaseCnt(paramMap);
			finalmap.put("mdcCaseCntByCode", mdcCaseCnt);
			if(finalmap.get("hospoutcasecnt_temp")!="0"){
				finalmap.put("mdcCaseCntByCodeRatio", imputedRatio(Double.valueOf(mdcCaseCnt),Double.valueOf(finalmap.get("hospoutcasecnt_temp")+"")));		
			}else{
				finalmap.put("mdcCaseCntByCodeRatio","0");
			}
			int  mdcDRGsCnt = wordDRGsReportFacade.findMdcDRGsCnt(paramMap);
			int  mdcDRGsRealCnt = wordDRGsReportFacade.findMdcDRGsRealCnt(paramMap);
			finalmap.put("mdcDRGsCnt", mdcDRGsCnt);
			finalmap.put("mdcDRGsRealCnt", mdcDRGsRealCnt);
			if(mdcDRGsRealCnt!=0){
				finalmap.put("mdcDrgsCntByCodeRatio", imputedRatio(Double.valueOf(mdcDRGsCnt),Double.valueOf(mdcDRGsRealCnt)));
			}else{
				finalmap.put("mdcDrgsCntByCodeRatio","0");
			}
			paramMap.put("mdcCasecnt", mdcCaseCnt);
			List<Map<String,Object>>  mdcdrgtop10MapList = wordDRGsReportFacade.findmdcDdrgtop10MapList(paramMap);	
			finalmap.put("mdcdrgtop10MapList", mdcdrgtop10MapList);
			
			//该专业下病例数最多的前十个病组累计出院病例
			int mdcdrgcasetop10=0; 
			for(Map<String,Object> map:mdcdrgtop10MapList){
				int cnt=Integer.valueOf(map.get("outcase")==null?"0":map.get("outcase").toString().trim());
				mdcdrgcasetop10+=cnt;
			}
			finalmap.put("mdcdrgmostcasecnt",mdcdrgcasetop10);
			if(mdcCaseCnt!=0){
				finalmap.put("mdcDrgsCaseRatio", imputedRatio(Double.valueOf(mdcdrgcasetop10),Double.valueOf(mdcCaseCnt)));
			}else{
				finalmap.put("mdcDrgsCaseRatio","0");
			}
			//该专业下总权重最多的前十位的病组
			List<Map<String,Object>>  mdcdrgweighttop10MapList = wordDRGsReportFacade.findmdcdrgweighttop10List(paramMap);
			//计算该专业下总权重
			String mdctotalweightcount=wordDRGsReportFacade.findmdctotalweightcount(paramMap);
			double mdcdrgweighttop10=0;
			double mdctotalweight=0;
			for(Map<String,Object> map:mdcdrgweighttop10MapList){
				mdctotalweight=Double.valueOf(map.get("totalweight")==null?"0":map.get("totalweight").toString().trim());
				mdcdrgweighttop10+=mdctotalweight;
			}
			finalmap.put("mdcdrgweighttop10", mdcdrgweighttop10);
			if(mdctotalweight!=0){
				finalmap.put("mdcDrgsWeightRatio", imputedRatio(Double.valueOf(mdcdrgweighttop10),Double.valueOf(mdctotalweightcount).doubleValue()));
			}else{
				finalmap.put("mdcDrgsWeightRatio","0");
			}
			finalmap.put("mdcdrgweighttop10MapList", mdcdrgweighttop10MapList);
			
			//表格 13本院与标杆医院MDCH专业比较
			Object[]  listMDCbyTable27= wordDRGsReportFacade.findlistMDCbyTable27(paramMap);
			finalmap.put("mdcdrgcnt", Arith.dataFormat(listMDCbyTable27[0]==null?"0":listMDCbyTable27[0].toString().trim(), "2"));
			finalmap.put("mdccmi", Arith.dataFormat(listMDCbyTable27[1]==null?"0":listMDCbyTable27[1].toString().trim(), "1"));
			finalmap.put("mdcefftime", Arith.dataFormat(listMDCbyTable27[3]==null?"0":listMDCbyTable27[3].toString().trim(), "1"));
			finalmap.put("mdceffcost", Arith.dataFormat(listMDCbyTable27[2]==null?"0":listMDCbyTable27[2].toString().trim(), "1"));
			finalmap.put("mdcrisk1ratio", Arith.dataFormat(listMDCbyTable27[4]==null?"0":listMDCbyTable27[4].toString().trim(), "1"));
			finalmap.put("mdcrisk2ratio", Arith.dataFormat(listMDCbyTable27[5]==null?"0":listMDCbyTable27[5].toString().trim(), "1"));	
		
			//***********************************第六章开始*************************************************************
			// 获取未入组原因
			List<Object[]> notInGroupReasonList = wordDRGsReportFacade.findNotInGroupReason(paramMap);
			int reasonOne=0;
			int reasonTwo=0;
			int reasonThr=0;
			int reasonFou=0;
			int reasonFiv=0;
			int reasonSix=0;
			int reasonSev=0;
			int reasonEig=0;
			int reasonNin=0;
			int reasonTen=0;
			int reasonEvl=0;
			int reasonTwe=0;
			if(!notInGroupReasonList.isEmpty()){
				for(Object[] obj:notInGroupReasonList){
					if ("q_qY".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonOne = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("c_costAndDay".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonTwo = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("c_costOrDay".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonThr = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("c_cost".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonFou = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("c_day".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonFiv = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("md_noMDiag".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonSix = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("md_diagOutOfRange".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonSev = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("md_invalidMainDiag".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonEig = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("md_diagCanNotGroup".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonNin = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					}  else if ("n_ageOrWeightEtcErr".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonTen = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("s_sexErr".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonEvl = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					} else if ("o_other".equals(obj[0] == null ? "" : obj[0].toString().trim()) ) {
						reasonTwe = Double.valueOf(obj[1] == null ? "0" : obj[1].toString()).intValue();
					}
					
				}
			}
			String notingroupreason="";
			int notingroupreasoncnt=0;
			if(reasonOne!=0){
				notingroupreasoncnt++;
				notingroupreason+="手术/操作与诊断不符、";
			}
			if(reasonTwo!=0){
				notingroupreasoncnt++;
				notingroupreason+="费用和住院日均异常、";
			}
			if(reasonThr!=0){
				notingroupreasoncnt++;
				notingroupreason+="费用或住院日异常、";
			}
		    if(reasonFou!=0){
				notingroupreasoncnt++;
				notingroupreason+="费用异常、";
			}
			if(reasonFiv!=0){
				notingroupreasoncnt++;
				notingroupreason+="住院日异常、";
			}
			if(reasonSix!=0){
				notingroupreasoncnt++;
				notingroupreason+="主要诊断缺失、";
			}
			if(reasonSev!=0){
				notingroupreasoncnt++;
				notingroupreason+="主要诊断编码不在北京临床版范围内、";
			}
			if(reasonEig!=0){
				notingroupreasoncnt++;
				notingroupreason+="无效的主要诊断编码、";
			}
			if(reasonNin!=0){
				notingroupreasoncnt++;
				notingroupreason+="主要诊断编码不在分组范围内、";
			}
			if(reasonTen!=0){
				notingroupreasoncnt++;
				notingroupreason+="年龄/新生儿天数、体重等异常、";
			}
			if(reasonEvl!=0){
				notingroupreasoncnt++;
				notingroupreason+="主要诊断编码与性别不符、";
			}
			if(reasonTwe!=0){
				notingroupreasoncnt++;
				notingroupreason+="其他原因、";
			}
			if(notingroupreason.length()>1){
				notingroupreason=notingroupreason.substring(0, notingroupreason.length()-1);
			}
			finalmap.put("notingroupreasoncnt", notingroupreasoncnt);
			finalmap.put("notingroupreason", notingroupreason);
			finalmap.put("reasonOne", reasonOne);
			finalmap.put("reasonTwo", reasonTwo);
			finalmap.put("reasonThr", reasonThr);
			finalmap.put("reasonFou", reasonFou);
			finalmap.put("reasonFiv", reasonFiv);
			finalmap.put("reasonSix", reasonSix);
			finalmap.put("reasonSev", reasonSev);
			finalmap.put("reasonEig", reasonEig);
			finalmap.put("reasonNin", reasonNin);
			finalmap.put("reasonTen", reasonTen);
			finalmap.put("reasonEvl", reasonEvl);
			finalmap.put("reasonTwe", reasonTwe);
			
			// 大于60天的病例科室分布
			List<Object[]> depOver60List = wordDRGsReportFacade.findDepOver60List(paramMap);
			List<Map<String, Object>> depOver60MapList = new ArrayList<Map<String, Object>>();
			if (depOver60List.size() > 0) {
				int i=1;
				for (Object[] obj : depOver60List) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("order", i);
					map.put("depname", obj[0]==null?"--":obj[0].toString());
					map.put("casecnt", Arith.dataFormat(obj[1]==null?"0":obj[1].toString().trim(), "2"));
					if(finalmap.get("over60casecnt_temp")!="0"){
						map.put("casecntRatio", Arith.mul(Arith.div(Double.valueOf(obj[1] == null ? "0" : obj[1]+""), Double.valueOf(finalmap.get("over60casecnt_temp")+""), 4), 100));
					}else{
						map.put("casecntRatio","0");
					}
					depOver60MapList.add(map);
					i++;
				}
			}
			finalmap.put("depOver60MapList", depOver60MapList);
	
			 //未入组病例科室分布
			List<Map<String, Object>> notInGroupCaseByDepMapList = new ArrayList<Map<String, Object>>();
			List<Object[]> notInGroupCaseByDepList = wordDRGsReportFacade.findNotInGroupCaseByDepList(paramMap);
			if (notInGroupCaseByDepList.size() > 0) {
				int i=1;
				for (Object[] obj : notInGroupCaseByDepList) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("order", i);
					map.put("depname", obj[0]==null?"--":obj[0]);
					map.put("casecnt", Arith.dataFormat(obj[1]==null?"0":obj[1].toString().trim(), "2"));
					if(finalmap.get("notingroupcasecnt_temp")!="0"){
						map.put("casecntRatio", Arith.mul(Arith.div(Double.valueOf(obj[1] == null ? "0" : obj[1].toString().trim()), Double.valueOf(finalmap.get("notingroupcasecnt_temp")+""), 4), 100));
					}else{
						map.put("casecntRatio", "0");
					}
					notInGroupCaseByDepMapList.add(map);
					i++;
				}
			}
			
			finalmap.put("notInGroupCaseByDepMapList", notInGroupCaseByDepMapList);
			
	
			//未入组病例主诊断分布
			 
			List<Object[]> notInGroupCaseByDiagList = wordDRGsReportFacade.findNotInGroupCaseByDiagList(paramMap);
			List<Map<String, Object>> notInGroupCaseByDiagMapList = new ArrayList<Map<String, Object>>();
			if (notInGroupCaseByDiagList.size() > 0) {
				int i=1;
				for (Object[] obj : notInGroupCaseByDiagList) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("order",i);
					map.put("code", obj[0]==null?"--":obj[0].toString());
					map.put("desc", obj[1]==null?"--":obj[1].toString());
					map.put("cnt", Arith.dataFormat(obj[2]==null?"0":obj[2].toString().trim(), "2"));
					if(finalmap.get("notingroupcasecnt_temp")!="0"){
						map.put("ratio", Arith.mul(Arith.div(Double.valueOf(obj[2] == null ? "0" : obj[2]+""), Double.valueOf(finalmap.get("notingroupcasecnt_temp")+""), 4), 100));
					}else{
						map.put("ratio","0");
					}
					notInGroupCaseByDiagMapList.add(map);
					i++;
				}
			}
			finalmap.put("notInGroupCaseByDiagMapList", notInGroupCaseByDiagMapList);
		
			//未入组病例手术分布
			
			List<Object[]> notInGroupCaseByOperList = wordDRGsReportFacade.findNotInGroupCaseByOperList(paramMap);
			List<Map<String, Object>> notInGroupCaseByOperMapList = new ArrayList<Map<String, Object>>();
			if (notInGroupCaseByOperList.size() > 0) {
				int i=1;
				for (Object[] obj : notInGroupCaseByOperList) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("order", i);
					map.put("code", obj[0]==null?"--":obj[0].toString().trim());
					map.put("desc", obj[1]==null?"--":obj[1].toString().trim());
					map.put("cnt", Arith.dataFormat(obj[2]==null?"0":obj[2].toString().trim(), "2"));
					if(finalmap.get("notingroupcasecnt_temp")!="0"){
						map.put("ratio", Arith.mul(Arith.div(Double.valueOf(obj[2] == null ? "0" : obj[2]+""), Double.valueOf(finalmap.get("notingroupcasecnt_temp")+""), 4), 100));
					}else{
						map.put("ratio","0");
					}
					
					notInGroupCaseByOperMapList.add(map);
					i++;
				}
			}
			finalmap.put("notInGroupCaseByOperMapList", notInGroupCaseByOperMapList);
			
			/**
			 * mdc专业drg覆盖率
			 */
			StringBuffer mdcCodetop5 = new StringBuffer();
			String  MDCCodetop5="";
			List<Object[]> mdcDrgsTop5List = wordDRGsReportFacade.findMdcDrgsTop5List(paramMap);
			String mdcCodeLast5 ="--";
			if (mdcDrgsTop5List.size() > 0) {
				for (Object[] obj : mdcDrgsTop5List) {
						mdcCodetop5.append("'" + obj[0] + "',");
				}
			}
			if(mdcCodetop5.length()>0){
				 mdcCodeLast5 = mdcCodetop5.substring(0, mdcCodetop5.lastIndexOf(",")).toString();
			}
			if (mdcDrgsTop5List.size() > 0) {
				for (Object[] obj : mdcDrgsTop5List) {
					MDCCodetop5+=obj[2]+"、";
				}
			}
			if(MDCCodetop5.length()>1){
				MDCCodetop5=MDCCodetop5.substring(0, MDCCodetop5.length()-1);
			}
			// 本院由低到高小于前五的mdc专业下缺失的drg的权重大于1和大于9的
			List<Object[]> mdcDrgsByWeightOver1List = wordDRGsReportFacade.findMdcDrgsByWeightOver1List(paramMap, mdcCodeLast5);
             int mdcweightover1cnt=mdcDrgsByWeightOver1List.size();
             int overweight9cnt=0;
             List<Map<String, Object>> mdcDrgsByWeightOver1MapList = new ArrayList<Map<String, Object>>();
             String mdcweighOver9Str="-";              
			if (mdcDrgsByWeightOver1List.size() > 0) {
				int i=1;
				for (Object[] obj : mdcDrgsByWeightOver1List) {
					Map<String, Object> map = new HashMap<String, Object>();
					String code=obj[1]==null?"":obj[1].toString().trim();
					String desc=obj[2]==null?"":obj[2].toString().trim();
					//生成的DRG相关数据做大小于号的相关判断处理，防止打开报xml架构无效的bug
					if(desc.contains("<")){
						desc=desc.replace("<", "小于");
					}else if(desc.contains(">")){
						desc=desc.replace(">", "大于");
					}else{
					}
					map.put("order", i);
					map.put("code", obj[0]==null?"--":obj[0].toString().trim());
					map.put("desc", code + "(" + desc+ ")");
					map.put("weight", obj[3]==null?"0.00":Arith.dataFormat(obj[3]+"", "3"));
					mdcDrgsByWeightOver1MapList.add(map);
					i++;
				}
			}
			List<Object[]> mdcDrgsByWeightOver9List = wordDRGsReportFacade.findMdcDrgsByWeightOver9List(paramMap, mdcCodeLast5);
			StringBuffer mdcdesc = new StringBuffer();
			for (Object[] obj : mdcDrgsByWeightOver9List) {	
				  mdcdesc.append(obj[1] + "(" + obj[2] + ")、");  	 
			}
			overweight9cnt=mdcDrgsByWeightOver9List.size();
			if(mdcdesc.length()>0){
				mdcweighOver9Str=mdcdesc.substring(0, mdcdesc.lastIndexOf("、"))+ "";
			}
			if(MDCCodetop5.length()<1){
				finalmap.put("mdcCodeLast5","--");
			}else{
				finalmap.put("mdcCodeLast5", MDCCodetop5);
			}
			
			finalmap.put("mdcweightover1cnt", Arith.dataFormat(mdcweightover1cnt+"", "2"));
			finalmap.put("overweight9cnt", Arith.dataFormat(overweight9cnt+"", "2"));
			if(mdcweighOver9Str.length()<1){
				finalmap.put("mdcweighOver9Str", "--");
			}else{
				finalmap.put("mdcweighOver9Str", mdcweighOver9Str);
			}
			finalmap.put("mdcDrgsByWeightOver1MapList", mdcDrgsByWeightOver1MapList);
			   
				// 病组的时间消耗指数
				List<Object[]> drgsTimeList = wordDRGsReportFacade.findDrgsTimeList(paramMap);
				int mdctimeThan1= drgsTimeList.size();
				String mdctimeThan1ratio="0";
				if(finalmap.get("hospdrgcnt")!="0"){
					 mdctimeThan1ratio=(Arith.mul(Arith.div(Double.valueOf(drgsTimeList.size()), Double.valueOf(finalmap.get("hospdrgcnt")+""), 4), 100))+"";
				}
				String drgstimestr="--";
				String drgstimecntstr="--";					
				if (drgsTimeList.size() > 0) {
					StringBuffer drgstime = new StringBuffer();
					StringBuffer drgstimecnt = new StringBuffer();
					int index = 0;
					for (Object[] obj : drgsTimeList) {
						if (index < 3) {
							String desc=obj[1]==null?"":obj[1].toString().trim();
							//生成的DRG相关数据做大小于号的相关判断处理，防止打开报xml架构无效的bug
							if(desc.contains("<")){
								desc=desc.replace("<", "小于");
							}else if(desc.contains(">")){
								desc=desc.replace(">", "大于");
							}else{
							}
							drgstime.append(obj[0] + "(" + desc + ")、");
							drgstimecnt.append(Arith.round(Double.valueOf(obj[2] == null ? "0" : obj[2].toString()), 2) + "、");
						}
						index++;
					}
					if(drgstime.length()>0){
						drgstimestr=drgstime.substring(0, drgstime.lastIndexOf("、")).toString() + "";
					}
					if(drgstimecnt.length()>0){
						drgstimecntstr=drgstimecnt.substring(0, drgstimecnt.lastIndexOf("、")).toString() + "";
					}
				}
				finalmap.put("mdctimeThan1", Arith.dataFormat(mdctimeThan1+"", "2"));
				finalmap.put("mdctimeThan1ratio", Arith.dataFormat(mdctimeThan1ratio+"", "1"));
				if(drgstimestr.length()<1){
					finalmap.put("drgstimestr","--");
				}else{
					finalmap.put("drgstimestr", drgstimestr);
				}
				if(drgstimecntstr.length()<1){
					finalmap.put("drgstimecntstr", "--");
				}else{
					finalmap.put("drgstimecntstr", drgstimecntstr);
				}
			
				  
				// DRGS的费用消耗指数
				List<Object[]> drgsFeeList = wordDRGsReportFacade.findDrgsFeeList(paramMap);
				int mdcfeeThan1= drgsFeeList.size();
				
				String mdcfeeThan1ratio="0";
				if(finalmap.get("hospdrgcnt")!="0"){
					mdcfeeThan1ratio=(Arith.mul(Arith.div(Double.valueOf(drgsFeeList.size()), Double.valueOf(finalmap.get("hospdrgcnt")+""), 4), 100))+"";
				}
				String drgsfeestr="--";
				String drgsfeecntstr="--";					
				if (drgsFeeList.size() > 0) {
					StringBuffer drgsfee = new StringBuffer();
					StringBuffer drgsfeecnt = new StringBuffer();
					int index = 0;
					for (Object[] obj : drgsFeeList) {
						if (index < 3) {
							String desc=obj[1]==null?"":obj[1].toString().trim();
							//生成的DRG相关数据做大小于号的相关判断处理，防止打开报xml架构无效的bug
							if(desc.contains("<")){
								desc=desc.replace("<", "小于");
							}else if(desc.contains(">")){
								desc=desc.replace(">", "大于");
							}else{
							}
							drgsfee.append(obj[0] + "(" + desc + ")、");
							drgsfeecnt.append(Arith.round(Double.valueOf(obj[2] == null ? "0" : obj[2].toString()), 2) + "、");
						}
						index++;
					}
					if(drgsfee.length()>0){
						drgsfeestr=drgsfee.substring(0, drgsfee.lastIndexOf("、")).toString() + "";
					}
					if(drgsfeecnt.length()>0){
						drgsfeecntstr=drgsfeecnt.substring(0, drgsfeecnt.lastIndexOf("、")).toString() + "";
					}
			
				}
				finalmap.put("mdcfeeThan1", Arith.dataFormat(mdcfeeThan1+"", "2"));
				finalmap.put("mdcfeeThan1ratio", Arith.dataFormat(mdcfeeThan1ratio+"", "1"));
				if(drgsfeestr.length()<1){
					finalmap.put("drgsfeestr", "--");
				}else{
					finalmap.put("drgsfeestr", drgsfeestr);
				}
				if(drgsfeecntstr.length()<1){
					finalmap.put("drgsfeecntstr", "--");
				}else{
					finalmap.put("drgsfeecntstr", drgsfeecntstr);
				}
			
				
	           //--------------------附表------------------------------------------------------		
			    //附表1 全院及各科室医疗服务综合能力情况表
				//全院指标
				List<Object[]> hospAbilityList = wordDRGsReportFacade.findHospAbilityList(paramMap);
				if (hospAbilityList.size() > 0) {
					    Object[] obj=hospAbilityList.get(0);
						finalmap.put("allhospincnt", obj[0]==null?"0":Arith.dataFormat(obj[0].toString(), "2"));
						finalmap.put("allhospcmi", obj[1]==null?"0.00":Arith.dataFormat(obj[1].toString(), "1"));
						finalmap.put("allhosprealdrgscnt", obj[2]==null?"0":Arith.dataFormat(obj[2].toString(), "2"));
						finalmap.put("allhospweight", obj[3]==null?"0.00":Arith.dataFormat(obj[3].toString(), "3"));
						finalmap.put("allhosptime", obj[4]==null?"0.00":Arith.dataFormat(obj[4].toString(), "1"));
						finalmap.put("allhospfee", obj[5]==null?"0.00":Arith.dataFormat(obj[5].toString(), "1"));
						finalmap.put("allhosplratio", obj[6]==null?"0.00":Arith.dataFormat(obj[6].toString(), "1"));
						finalmap.put("allhospmlratio", obj[7]==null?"0.00":Arith.dataFormat(obj[7].toString(), "1"));
					  }
			
				
				//科室指标
				List<Object[]> depAbilityList = wordDRGsReportFacade.findDepAbilityList(paramMap);
				List<Map<String, Object>> finalDepAbilityList = new ArrayList<Map<String, Object>>();
				if (depAbilityList.size() > 0) {
					int i=1;
					for (Object[] obj : depAbilityList) {
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("depname", obj[0]==null?"--":(obj[0]+"").trim());
						map.put("incnt", obj[1]==null?"0":Arith.dataFormat(obj[1].toString(), "2"));
						map.put("cmi", obj[2]==null?"0.00":Arith.dataFormat(obj[2].toString(), "1"));
						map.put("drgscnt", obj[3]==null?"0":Arith.dataFormat(obj[3].toString(), "2"));
						map.put("weight", obj[4]==null?"0.00":Arith.dataFormat(obj[4].toString(), "3"));
						map.put("time", obj[5]==null?"0.00":Arith.dataFormat(obj[5].toString(), "1"));
						map.put("fee", obj[6]==null?"0.00":Arith.dataFormat(obj[6].toString(), "1"));
						map.put("lratio", obj[7]==null?"0.00":Arith.dataFormat(obj[7].toString(), "1"));
						map.put("mlratio", obj[8]==null?"0.00":Arith.dataFormat(obj[8].toString(), "1"));
						finalDepAbilityList.add(map);
						i++;
					}
				}
				finalmap.put("finalDepAbilityList", finalDepAbilityList);
				
				//附表2 全院及各MDC专业DRGs病组覆盖情况及医疗服务综合能力情况表
				
				//全院指标
				List<Object[]> hospallDRGsList = wordDRGsReportFacade.findHospallDRGsList(paramMap);
				if (hospallDRGsList.size() > 0) {
					    Object[] obj=hospallDRGsList.get(0);
						finalmap.put("allhospdrgscnt", obj[0]==null?"0":Arith.dataFormat(obj[0].toString(), "2"));
						finalmap.put("allhospdrgsratio", obj[1]==null?"0.00":Arith.dataFormat(obj[1].toString(), "1"));
				}
				
				//各MDC指标
				List<Object[]> mdcAbilityList = wordDRGsReportFacade.findMDCAbilityList(paramMap);
				List<Map<String, Object>> finalMDCAbilityList = new ArrayList<Map<String, Object>>();
				if (mdcAbilityList.size() > 0) {
					int i=1;
					for (Object[] obj : mdcAbilityList) {
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("mdc", obj[0]==null?"--":(obj[0]+"").trim());
						map.put("desc", obj[1]==null?"--":(obj[1]+"").trim());
						map.put("incnt", obj[2]==null?"0":Arith.dataFormat(obj[2].toString(), "2"));
						map.put("drgsallcnt", obj[3]==null?"0":Arith.dataFormat(obj[3].toString(), "2"));
						map.put("drgsratio", obj[4]==null?"0":Arith.dataFormat(obj[4].toString(), "1"));
						map.put("cmi", obj[5]==null?"0.00":Arith.dataFormat(obj[5].toString(), "1"));
						map.put("drgsrealcnt", obj[6]==null?"0":Arith.dataFormat(obj[6].toString(), "2"));
						map.put("weight", obj[7]==null?"0.00":Arith.dataFormat(obj[7].toString(), "3"));
						map.put("time", obj[8]==null?"0.00":Arith.dataFormat(obj[8].toString(), "1"));
						map.put("fee", obj[9]==null?"0.00":Arith.dataFormat(obj[9].toString(), "1"));
						map.put("lratio", obj[10]==null?"0.00":Arith.dataFormat(obj[10].toString(), "1"));
						map.put("mlratio", obj[11]==null?"0.00":Arith.dataFormat(obj[11].toString(), "1"));
						finalMDCAbilityList.add(map);
						i++;
					}
				}
				finalmap.put("finalMDCAbilityList", finalMDCAbilityList);
				
				//附表3 住院病例DRGs总权重最高的前二十位主治医师
				List<Object[]> docByWeightList = wordDRGsReportFacade.findDocByWeightList(paramMap);
				List<Map<String, Object>> DocByWeightList = new ArrayList<Map<String, Object>>();
				if (docByWeightList.size() > 0) {
					int i=1;
					for (Object[] obj : docByWeightList) {
						if(i<=20){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("doc", obj[0]==null?"--":(obj[0]+"").trim());
						map.put("dep", obj[1]==null?"--":(obj[1]+"").trim());
						map.put("cmi", obj[4]==null?"0.00":Arith.dataFormat(obj[4].toString(), "1"));
						map.put("drgscnt", obj[3]==null?"0":Arith.dataFormat(obj[3].toString(), "2"));
						map.put("weight", obj[2]==null?"0":Arith.dataFormat(obj[2].toString(), "3"));
						map.put("incnt", obj[9]==null?"0":Arith.dataFormat(obj[9].toString(), "2"));
						map.put("time", obj[5]==null?"0.00":Arith.dataFormat(obj[5].toString(), "1"));
						map.put("fee", obj[6]==null?"0.00":Arith.dataFormat(obj[6].toString(), "1"));
						map.put("lratio",obj[7]==null?"0.00":Arith.dataFormat(obj[7].toString(), "1"));
						map.put("mlratio",obj[8]==null?"0.00":Arith.dataFormat(obj[8].toString(), "1"));
						DocByWeightList.add(map);
						i++;
						}
					}
				}
				finalmap.put("DocByWeightList", DocByWeightList);
				
				//附表4 CMI值最高的前二十位主治医师
				List<Object[]> docByCMIList = wordDRGsReportFacade.findDocByCMIList(paramMap);
				List<Map<String, Object>> DocByCMIList = new ArrayList<Map<String, Object>>();
				if (docByCMIList.size() > 0) {
					int i=1;
					for (Object[] obj : docByCMIList) {
						if(i<=20){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("order", i);
						map.put("doc", obj[0]==null?"--":(obj[0]+"").trim());
						map.put("dep", obj[1]==null?"--":(obj[1]+"").trim());
						map.put("cmi", obj[4]==null?"0.00":Arith.dataFormat(obj[4].toString(), "1"));
						map.put("drgscnt", obj[3]==null?"0":Arith.dataFormat(obj[3].toString(), "2"));
						map.put("weight", obj[2]==null?"0":Arith.dataFormat(obj[2].toString(), "3"));
						map.put("incnt", obj[9]==null?"0":Arith.dataFormat(obj[9].toString(), "2"));
						map.put("time", obj[5]==null?"0.00":Arith.dataFormat(obj[5].toString(), "1"));
						map.put("fee", obj[6]==null?"0.00":Arith.dataFormat(obj[6].toString(), "1"));
						map.put("lratio",obj[7]==null?"0.00":Arith.dataFormat(obj[7].toString(), "1"));
						map.put("mlratio",obj[8]==null?"0.00":Arith.dataFormat(obj[8].toString(), "1"));
						DocByCMIList.add(map);
						i++;
						}
					}
				}
				finalmap.put("DocByCMIList", DocByCMIList);
				
				//附表5 未入组病例覆盖的所有主要诊断
				List<Object[]>  oldNotInGroupDiagList=wordDRGsReportFacade.findNotInGroupDiagList(paramMap);
				List<Map<String, Object>> notInGroupDiagList = new ArrayList<Map<String, Object>>();
				if (oldNotInGroupDiagList.size() > 0) {
					int leftcnt=0;
					//判断是奇数的情况
					if(oldNotInGroupDiagList.size()%2==1){
						 leftcnt=(oldNotInGroupDiagList.size()+1)/2;
					}else{
						//当为偶数的情况
					     leftcnt=oldNotInGroupDiagList.size()/2;
					}
					for (int j = 0; j < leftcnt; j++) {
						Map<String, Object> map=new HashMap<String, Object>();
						//当为奇数最后一位右边设置为空
						if((oldNotInGroupDiagList.size()%2==1)&&(j==leftcnt-1)){
							Object[] objL=oldNotInGroupDiagList.get(j);
							map.put("orderL",j+1);
							map.put("codeL", objL[0]==null?"--":(objL[0]+"").trim());
							map.put("descL", objL[1]==null?"--":(objL[1]+"").trim());
							map.put("cntL", objL[2]==null?"0":Arith.dataFormat(objL[2].toString(), "2"));
							map.put("radioL", objL[3]==null?"0.00":(objL[3]+"").trim());
							map.put("orderR", "");
							map.put("codeR", "");
							map.put("descR", "");
							map.put("cntR", "");
							map.put("radioR", "");
							notInGroupDiagList.add(map);
						}else{
							Object[] objL=oldNotInGroupDiagList.get(j);
							Object[] objR=oldNotInGroupDiagList.get(j+leftcnt);
							map.put("orderL",j+1);
							map.put("codeL", objL[0]==null?"--":(objL[0]+"").trim());
							map.put("descL", objL[1]==null?"--":(objL[1]+"").trim());
							map.put("cntL", objL[2]==null?"0":Arith.dataFormat(objL[2].toString(), "2"));
							map.put("radioL", objL[3]==null?"0.00":(objL[3]+"").trim());
							map.put("orderR", j+leftcnt+1);
							map.put("codeR", objR[0]==null?"--":(objR[0]+"").trim());
							map.put("descR", objR[1]==null?"--":(objR[1]+"").trim());
							map.put("cntR", objR[2]==null?"0":Arith.dataFormat(objR[2].toString(), "2"));
							map.put("radioR", objR[3]==null?"0.00":(objR[3]+"").trim());
							notInGroupDiagList.add(map);
						}
					}
				}
				finalmap.put("notInGroupDiagList", notInGroupDiagList);
			
				//附表6   未入组病例覆盖的所有主要手术/操作
				List<Object[]>  oldNotInGroupOperList=wordDRGsReportFacade.findNotInGroupOperList(paramMap);
				List<Map<String, Object>> notInGroupOperList = new ArrayList<Map<String, Object>>();
				if (oldNotInGroupOperList.size() > 0) {
					int leftcnt=0;
					//判断是奇数的情况
					if(oldNotInGroupOperList.size()%2==1){
						 leftcnt=(oldNotInGroupOperList.size()+1)/2;
					}else{
						//当为偶数的情况
					     leftcnt=oldNotInGroupOperList.size()/2;
					}
					for (int j = 0; j < leftcnt; j++) {
						Map<String, Object> map=new HashMap<String, Object>();
						//当为奇数最后一位右边设置为空
						if((oldNotInGroupOperList.size()%2==1)&&(j==leftcnt-1)){
							Object[] objL=oldNotInGroupOperList.get(j);
							map.put("orderL",j+1);
							map.put("codeL", objL[0]==null?"--":(objL[0]+"").trim());
							map.put("descL", objL[1]==null?"--":(objL[1]+"").trim());
							map.put("cntL", objL[2]==null?"0":Arith.dataFormat(objL[2].toString(), "2"));
							map.put("radioL", objL[3]==null?"0.00":(objL[3]+"").trim());
							map.put("orderR", "");
							map.put("codeR", "");
							map.put("descR", "");
							map.put("cntR", "");
							map.put("radioR", "");
							notInGroupOperList.add(map);
						}else{
							Object[] objL=oldNotInGroupOperList.get(j);
							Object[] objR=oldNotInGroupOperList.get(j+leftcnt);
							map.put("orderL",j+1);
							map.put("codeL", objL[0]==null?"--":(objL[0]+"").trim());
							map.put("descL", objL[1]==null?"--":(objL[1]+"").trim());
							map.put("cntL", objL[2]==null?"0":Arith.dataFormat(objL[2].toString(), "2"));
							map.put("radioL", objL[3]==null?"0.00":(objL[3]+"").trim());
							map.put("orderR", j+leftcnt+1);
							map.put("codeR", objR[0]==null?"--":(objR[0]+"").trim());
							map.put("descR", objR[1]==null?"--":(objR[1]+"").trim());
							map.put("cntR", objR[2]==null?"0":Arith.dataFormat(objR[2].toString(), "2"));
							map.put("radioR", objR[3]==null?"0.00":(objR[3]+"").trim());
							notInGroupOperList.add(map);
						}
					}
				}
				finalmap.put("notInGroupOperList", notInGroupOperList);
				
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return InvokeResult.success(finalmap);
			}
		}else{
			return InvokeResult.failure("生成文档失败");
		}
	
	}
	/**
	 * 
	 * @Description : 生成分析报告
	 * @methodname :createWordReport
	 * @author:ShaoZhiYuan
	 * @return InvokeResult
	 * @date :2017年2月20日
	 */
	@ResponseBody
	@RequestMapping(value = "createWordReport")
	public InvokeResult createWordReport() {
		Map<String,Object> map=new HashMap<String,Object>();
		long start = System.currentTimeMillis();
		long reportNo = System.currentTimeMillis();
		File folder = new File(new File(ResourceLoader.getPath("")).getParentFile().getParent() + "/tmp/");
		if (!folder.exists()) {
			folder.mkdirs();
		}
		String outputFile = folder.getPath() + File.separator + reportNo + ".doc";
		try {
			Configuration configuration = new Configuration();
			configuration.setDefaultEncoding("UTF-8");
			configuration.setClassForTemplateLoading(WordDRGsReportController.class, "/config/templates/");
			Template template = configuration.getTemplate("DRGsReport.xml");
			FileOutputStream fos = new FileOutputStream(new File(outputFile));
			Writer writer = new OutputStreamWriter(fos);
			template.process(finalmap, writer);
			writer.close();
			System.err.println(" \n 文档生成成功 path=\n" + outputFile);
			System.err.println("生成文档耗时time=" + (System.currentTimeMillis() - start) / 1000);
			map.put("patch", "tmp/"+reportNo+".doc");
			map.put("hospname", finalmap.get("hospName"));
			return InvokeResult.success(map);
		} catch (Exception e) {
			e.printStackTrace();
			return InvokeResult.failure("生成文档失败[" + e.getMessage() + "]");
		}
	}
	/**
	 * @methodname :imputedRatio
	 * @Description : 计算百分比
	 * @author:LiuHongjun
	 * @return Double
	 * @date :2016年9月10日
	 */
	public Double imputedRatio(Double a, Double b) {
		return Arith.mul(Arith.div(a, b, 4), 100);
	}
	/**
	 * @methodname :imputedMiddle
	 * @Description : 计算中位数
	 * @author:LiuHongjun
	 * @return Double
	 * @date :2016年9月11日
	 */
	public Double imputedMiddleWeight(List<Map<String, Object>> list) {
		Double middledata=0.0;
		List<Double> doublelist = new ArrayList<Double>();
		for (Map<String, Object> objlist : list) {
			doublelist.add(Double.valueOf((objlist.get("weight") == null ? 0 :objlist.get("weight")) + ""));
		}
		Collections.sort(doublelist);// 排序科室权重
		if (doublelist.size() % 2 == 0) {
			middledata =Arith.round(Arith.div(doublelist.get((doublelist.size() / 2) - 1) + doublelist.get(doublelist.size() / 2), 2), 2) ;
		} else {
			middledata = Arith.round(doublelist.get(((doublelist.size() +1)/ 2)-1),2);
		}
		return middledata;
	}
	/**
	 * @methodname :imputedMiddle
	 * @Description : 计算中位数cmi值
	 * @author:LiuHongjun
	 * @return Double
	 * @date :2016年9月11日
	 */
	public Double imputedMiddleCmi(List<Map<String, Object>> list) {
		Double middledata=0.0;
		List<Double> doublelist = new ArrayList<Double>();
		for (Map<String, Object> objlist : list) {
			doublelist.add(Double.valueOf((objlist.get("cmi") == null ? 0 :objlist.get("cmi")) + ""));
		}
		Collections.sort(doublelist);// 排序科室权重
		if (doublelist.size() % 2 == 0) {
			middledata =Arith.round(Arith.div(doublelist.get((doublelist.size() / 2) - 1) + doublelist.get(doublelist.size() / 2), 2), 2) ;
		} else {
			middledata = Arith.round(doublelist.get(((doublelist.size() +1)/ 2)-1),2);
		}
		return middledata;
	}
	/**
	 * @methodname :imputedMiddle
	 * @Description : 计算中位数费用
	 * @author:LiuHongjun
	 * @return Double
	 * @date :2016年9月11日
	 */
	public Double imputedMiddleFee(List<Map<String, Object>> list) {
		Double middledata=0.0;
		List<Double> doublelist = new ArrayList<Double>();
		for (Map<String, Object> objlist : list) {
			doublelist.add(Double.valueOf((objlist.get("feeEff") == null ? 0 :objlist.get("feeEff")) + ""));
		}
		Collections.sort(doublelist);// 排序科室权重
		if (doublelist.size() % 2 == 0) {
			middledata =Arith.round(Arith.div(doublelist.get((doublelist.size() / 2) - 1) + doublelist.get(doublelist.size() / 2), 2), 2) ;
		} else {
			middledata = Arith.round(doublelist.get(((doublelist.size() +1)/ 2)-1),2);
		}
		return middledata;
	}
	/**
	 * @methodname :imputedMiddle
	 * @Description : 计算中位数时间
	 * @author:LiuHongjun
	 * @return Double
	 * @date :2016年9月11日
	 */
	public Double imputedMiddleTime(List<Map<String, Object>> list) {
		Double middledata=0.0;
		List<Double> doublelist = new ArrayList<Double>();
		for (Map<String, Object> objlist : list) {
			doublelist.add(Double.valueOf((objlist.get("timeEff") == null ? 0 :objlist.get("timeEff")) + ""));
		}
		Collections.sort(doublelist);// 排序科室权重
		if (doublelist.size() % 2 == 0) {
			middledata =Arith.round(Arith.div(doublelist.get((doublelist.size() / 2) - 1) + doublelist.get(doublelist.size() / 2), 2), 2) ;
		} else {
			middledata = Arith.round(doublelist.get(((doublelist.size() +1)/ 2)-1),2);
		}
		return middledata;
	}
	/**
	 * 
	 *  analyzeMdc.  
	 *  @Description：分析重点病种
	 *  @Author LiuHongjun
	 *  @param request
	 *  @param response
	 *  @return 
	 *  @Date:2017年5月3日上午9:30:02
	 */
	@ResponseBody
	@RequestMapping(value = "analyzeMdc")
	public InvokeResult analyzeMdc(HttpServletRequest request,HttpServletResponse response) {
		 Map<String,Object> dto=new ParamMap().newMap(request);
		 String groupScheme=drgsIndexCalFacade.getGroupScheme();    //获取分组方案
		 String dateFrom=dto.get("dateFrom")==null?"":dto.get("dateFrom").toString();  //起始日期
		 String dateTo=dto.get("dateTo")==null?"":dto.get("dateTo").toString();        //终止日期
		 String stdId=drgsIndexCalFacade.getStdID(dateFrom,dateTo);   //获取标杆定位id
		 return InvokeResult.success(wordDRGsReportFacade.analyzeMdc(dto,groupScheme,stdId));
	}
	/**
	 * 
	 *  findMDC.  
	 *  @Description：获取mdc
	 *  @Author LiuHongjun
	 *  @param request
	 *  @param response
	 *  @return 
	 *  @Date:2017年5月3日上午9:40:18
	 */
	@ResponseBody
	@RequestMapping(value = "findMDC")
	public InvokeResult findMDC(HttpServletRequest request,HttpServletResponse response) {
		String groupScheme=drgsIndexCalFacade.getGroupScheme();    //获取分组方案
		return InvokeResult.success(wordDRGsReportFacade.findMDC(groupScheme));
	}
}
